Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / 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.*;
13 import java.util.ArrayList;
14
15 /**
16  * Convenience object to write a file
17  *
18  *
19  *
20  */
21 public class WriteToFile {
22     private FileWriter fstream;
23     private BufferedWriter bufferOut;
24     private String fileName;
25
26     public WriteToFile(String name) throws IOException {
27         fileName = name;
28         fstream = new FileWriter(fileName);
29         bufferOut = new BufferedWriter(fstream);
30     }
31
32     public void save(ArrayList<String> entryList) throws IOException {
33         for (String entry : entryList) {
34             bufferOut.write(entry);
35             bufferOut.append('\n');
36         }
37         try {
38             this.bufferOut.flush();
39         } catch (IOException e) {
40             e.printStackTrace();
41         }
42     }
43
44     public boolean close() {
45         try {
46             bufferOut.close();
47             fstream.close();
48         } catch (IOException e) {
49             return false;
50         }
51         return true;
52     }
53 }