/*  Copyright (C) 2012  Nicholas Wright

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
/**
 * Convenience class for reading text files.
 * Handles file opening, buffering and closing.
 */
public class TextFileReader {
	public String read(File path) throws IOException{
		String readData = "";
		String read;

		FileReader fr = new FileReader(path);
		BufferedReader br = new BufferedReader(fr);

		while((read = br.readLine()) != null)
			readData += read+"\n";
		
		br.close();
		fr.close();

		return readData;
	}
	
	public String read(InputStream is) throws IOException{
		String readData = "";
		String read;
		Reader r = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(r);

		while((read = br.readLine()) != null)
			readData += read+"\n";
		
		br.close();
		r.close();

		return readData;
	}
	
	public String read(String path) throws IOException{
		return read(new File(path));
	}
}

@@ -921,16 +921,18 @@
 eader;%0D%0A
+%0D%0A
 /**%0D%0A * 
@@ -972,20 +972,16 @@
 t files.
-%0D%0A *
  Handles
@@ -1008,16 +1008,20 @@
 ring and
+%0D%0A *
  closing
@@ -1112,52 +1112,10 @@
 tion
+ 
 %7B
-%0D%0A%09%09String readData = %22%22;%0D%0A%09%09String read;%0D%0A
 %0D%0A%09%09
@@ -1159,138 +1159,37 @@
 %0D%0A%09%09
-BufferedReader br = new BufferedReader(fr);%0D%0A%0D%0A%09%09while((read = br.readLine()) != null)%0D%0A%09%09%09readData += read+%22%5Cn%22;%0D%0A%09%09%0D%0A%09%09br.close(
+String readData = readData(fr
 );%0D%0A
@@ -1218,32 +1218,42 @@
 urn readData
+.toString()
 ;%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09public St
@@ -1300,136 +1300,319 @@
 tion
+ 
 %7B%0D%0A%09%09
-String readData = %22%22;%0D%0A%09%09String read;%0D%0A%09%09Reader r = new InputStreamReader(is);%0D%0A%09%09BufferedReader br = new BufferedReader(r)
+Reader reader = new InputStreamReader(is);%0D%0A%09%09String readData = readData(reader);%0D%0A%09%09reader.close();%0D%0A%0D%0A%09%09return readData;%0D%0A%09%7D%0D%0A%0D%0A%09private String readData(Reader reader) throws IOException %7B%0D%0A%09%09BufferedReader br = new BufferedReader(reader);%0D%0A%09%09StringBuilder readData = new StringBuilder();%0D%0A%09%09String read
 ;%0D%0A%0D
@@ -1619,16 +1619,17 @@
 %0A%09%09while
+ 
 ((read =
@@ -1652,16 +1652,18 @@
 != null)
+ %7B
 %0D%0A%09%09%09rea
@@ -1671,45 +1671,92 @@
 Data
- += 
+.append(
 read
-+
+ + 
 %22%5Cn%22
+)
 ;%0D%0A%09%09
+%7D%0D%0A
 %0D%0A%09%09
-br.close(
+readData.deleteCharAt(readData.length() - 1
 );%0D%0A
+%0D%0A
 %09%09
+b
 r.cl
@@ -1786,16 +1786,26 @@
 Data
+.toString()
 ;%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09p
@@ -1853,16 +1853,17 @@
 xception
+ 
 %7B%0D%0A%09%09ret
@@ -1894,10 +1894,8 @@
 ;%0D%0A%09%7D%0D%0A%7D
-%0D%0A

Refactor TextFileReader