3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.utils;
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;
20 * Read object to read from file stream
26 public class ObjectReader {
27 private static Logger logger = LoggerFactory.getLogger(ObjectReader.class);
28 private FileInputStream fis;
29 public ObjectInputStream ois;
31 public ObjectReader() {
36 public Object read(IObjectReader reader, String file) {
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) {
54 } catch (IOException ioex) {
55 logger.error("Failed to close object input stream: {}",
62 } catch (IOException ioex) {
63 logger.error("Failed to close input file stream: {}", file);