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
24 public class ObjectWriter {
25 private static Logger logger = LoggerFactory.getLogger(ObjectWriter.class);
26 private FileOutputStream fos;
27 private ObjectOutputStream oos;
29 public ObjectWriter() {
34 public Status write(Object obj, String file) {
36 fos = new FileOutputStream(file);
37 oos = new ObjectOutputStream(fos);
39 } catch (FileNotFoundException fex) {
40 logger.error("Cannot create {} for writing", file);
41 return new Status(StatusCode.INTERNALERROR, "IO Error");
42 } catch (IOException ioex) {
43 logger.error("Failed to write to {}", file);
44 return new Status(StatusCode.INTERNALERROR, "IO Error");
49 } catch (IOException ioex) {
50 logger.error("Failed to close object output stream: {}",
57 } catch (IOException ioex) {
59 .error("Failed to close output file stream: {}",
64 return new Status(StatusCode.SUCCESS, null);