Make use of NetUtils.getBroadcastMacAddr()
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / utils / ReadFromFile.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.util.ArrayList;
13 import java.io.*;
14
15 /**
16  * Convenience object for reading from file
17  *
18  *
19  *
20  */
21 public class ReadFromFile {
22     private FileInputStream fileStream;
23     private File filePointer;
24
25     public ReadFromFile(String fileName) throws FileNotFoundException {
26         fileStream = new FileInputStream(fileName);
27         filePointer = new File(fileName); //needed to allow file deletion
28     }
29
30     public ArrayList<String> readFile() throws IOException {
31         DataInputStream dataInput = new DataInputStream(this.fileStream);
32         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInput));
33
34         ArrayList<String> lineList = new ArrayList<String>();
35         String line;
36         while ((line = bufferedReader.readLine()) != null) {
37             lineList.add(line);
38         }
39         bufferedReader.close();
40         dataInput.close();
41         fileStream.close();
42         return lineList;
43     }
44
45     public boolean delete() {
46         if (filePointer == null) {
47             return true;
48         }
49         return filePointer.delete();
50     }
51 }