Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / ObjectWriter.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.utils;
11
12 import java.io.FileNotFoundException;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.ObjectOutputStream;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Write object to write to file stream
22  *
23  */
24 @Deprecated
25 public class ObjectWriter {
26     private static Logger logger = LoggerFactory.getLogger(ObjectWriter.class);
27     private FileOutputStream fos;
28     private ObjectOutputStream oos;
29
30     public ObjectWriter() {
31         fos = null;
32         oos = null;
33     }
34
35     public Status write(Object obj, String file) {
36         try {
37             fos = new FileOutputStream(file);
38             oos = new ObjectOutputStream(fos);
39             oos.writeObject(obj);
40         } catch (FileNotFoundException fex) {
41             logger.error("Cannot create {} for writing", file);
42             return new Status(StatusCode.INTERNALERROR, "IO Error");
43         } catch (IOException ioex) {
44             logger.error("Failed to write to {}", file);
45             return new Status(StatusCode.INTERNALERROR, "IO Error");
46         } finally {
47             if (oos != null) {
48                 try {
49                     oos.close();
50                 } catch (IOException ioex) {
51                     logger.error("Failed to close object output stream: {}",
52                             file);
53                 }
54             }
55             if (fos != null) {
56                 try {
57                     fos.close();
58                 } catch (IOException ioex) {
59                     logger
60                             .error("Failed to close output file stream: {}",
61                                     file);
62                 }
63             }
64         }
65         return new Status(StatusCode.SUCCESS);
66     }
67 }