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.FileNotFoundException;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.ObjectOutputStream;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Write object to write to file stream
25 public class ObjectWriter {
26 private static Logger logger = LoggerFactory.getLogger(ObjectWriter.class);
27 private FileOutputStream fos;
28 private ObjectOutputStream oos;
30 public ObjectWriter() {
35 public Status write(Object obj, String file) {
37 fos = new FileOutputStream(file);
38 oos = new ObjectOutputStream(fos);
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");
50 } catch (IOException ioex) {
51 logger.error("Failed to close object output stream: {}",
58 } catch (IOException ioex) {
60 .error("Failed to close output file stream: {}",
65 return new Status(StatusCode.SUCCESS);