Merge "BUG-2329 Add test for anyxmls inside rpc resonse for netcfon-connector"
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / WriteToFile.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.BufferedWriter;
13 import java.io.FileWriter;
14 import java.io.IOException;
15 import java.util.ArrayList;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * Convenience object to write a file
22  *
23  *
24  *
25  */
26 public class WriteToFile {
27     protected static final Logger logger = LoggerFactory
28     .getLogger(WriteToFile.class);
29     private FileWriter fstream;
30     private BufferedWriter bufferOut;
31
32     public WriteToFile(String fileName) throws IOException {
33         fstream = new FileWriter(fileName);
34         bufferOut = new BufferedWriter(fstream);
35     }
36
37     public void save(ArrayList<String> entryList) throws IOException {
38         for (String entry : entryList) {
39             bufferOut.write(entry);
40             bufferOut.append('\n');
41         }
42         try {
43             this.bufferOut.flush();
44         } catch (IOException e) {
45             logger.error("",e);
46         }
47     }
48
49     public boolean close() {
50         try {
51             bufferOut.close();
52             fstream.close();
53         } catch (IOException e) {
54             return false;
55         }
56         return true;
57     }
58 }