Fix star import and enable checkstyle rule to prevent it.
[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.io.BufferedReader;
13 import java.io.DataInputStream;
14 import java.io.File;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.InputStreamReader;
19 import java.util.ArrayList;
20
21 /**
22  * Convenience object for reading from file
23  *
24  *
25  *
26  */
27 public class ReadFromFile {
28     private FileInputStream fileStream;
29     private File filePointer;
30
31     public ReadFromFile(String fileName) throws FileNotFoundException {
32         fileStream = new FileInputStream(fileName);
33         filePointer = new File(fileName); //needed to allow file deletion
34     }
35
36     public ArrayList<String> readFile() throws IOException {
37         DataInputStream dataInput = new DataInputStream(this.fileStream);
38         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInput));
39
40         ArrayList<String> lineList = new ArrayList<String>();
41         String line;
42         while ((line = bufferedReader.readLine()) != null) {
43             lineList.add(line);
44         }
45         bufferedReader.close();
46         dataInput.close();
47         fileStream.close();
48         return lineList;
49     }
50
51     public boolean delete() {
52         if (filePointer == null) {
53             return true;
54         }
55         return filePointer.delete();
56     }
57 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.