Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / ObjectReader.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.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15 import java.io.ObjectInputStream;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Read object to read from file stream
21  *
22  *
23  *
24  */
25 @Deprecated
26 public class ObjectReader {
27     private static Logger logger = LoggerFactory.getLogger(ObjectReader.class);
28     private FileInputStream fis;
29     public ObjectInputStream ois;
30
31     public ObjectReader() {
32         fis = null;
33         ois = null;
34     }
35
36     public Object read(IObjectReader reader, String file) {
37         Object obj = null;
38         try {
39             fis = new FileInputStream(file);
40             ois = new ObjectInputStream(fis);
41             obj = reader.readObject(ois);
42         } catch (FileNotFoundException fnfex) {
43             //logger.info("Cannot find {} for reading", file);
44         } catch (IOException ioex) {
45             logger.error("Failed to read from {}", file);
46         } catch (ClassNotFoundException cnfex) {
47             logger.error("Failed to interpret content of {}", file);
48         } catch (Exception e) {
49
50         } finally {
51             if (ois != null) {
52                 try {
53                     ois.close();
54                 } catch (IOException ioex) {
55                     logger.error("Failed to close object input stream: {}",
56                             file);
57                 }
58             }
59             if (fis != null) {
60                 try {
61                     fis.close();
62                 } catch (IOException ioex) {
63                     logger.error("Failed to close input file stream: {}", file);
64                 }
65             }
66         }
67         return obj;
68     }
69 }