Merge "BUG-2218: Keep existing link augmentations during discovery process"
[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 public class ObjectReader {
26     private static Logger logger = LoggerFactory.getLogger(ObjectReader.class);
27     private FileInputStream fis;
28     public ObjectInputStream ois;
29
30     public ObjectReader() {
31         fis = null;
32         ois = null;
33     }
34
35     public Object read(IObjectReader reader, String file) {
36         Object obj = null;
37         try {
38             fis = new FileInputStream(file);
39             ois = new ObjectInputStream(fis);
40             obj = reader.readObject(ois);
41         } catch (FileNotFoundException fnfex) {
42             //logger.info("Cannot find {} for reading", file);
43         } catch (IOException ioex) {
44             logger.error("Failed to read from {}", file);
45         } catch (ClassNotFoundException cnfex) {
46             logger.error("Failed to interpret content of {}", file);
47         } catch (Exception e) {
48
49         } finally {
50             if (ois != null) {
51                 try {
52                     ois.close();
53                 } catch (IOException ioex) {
54                     logger.error("Failed to close object input stream: {}",
55                             file);
56                 }
57             }
58             if (fis != null) {
59                 try {
60                     fis.close();
61                 } catch (IOException ioex) {
62                     logger.error("Failed to close input file stream: {}", file);
63                 }
64             }
65         }
66         return obj;
67     }
68 }