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
25 public class ObjectReader {
26 private static Logger logger = LoggerFactory.getLogger(ObjectReader.class);
27 private FileInputStream fis;
28 public ObjectInputStream ois;
30 public ObjectReader() {
35 public Object read(IObjectReader reader, String file) {
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) {
53 } catch (IOException ioex) {
54 logger.error("Failed to close object input stream: {}",
61 } catch (IOException ioex) {
62 logger.error("Failed to close input file stream: {}", file);