[freenet-cvs] r14965 - trunk/freenet/src/freenet/support/io

nextgens at freenetproject.org nextgens at freenetproject.org
Tue Sep 4 21:53:04 UTC 2007


Author: nextgens
Date: 2007-09-04 21:53:04 +0000 (Tue, 04 Sep 2007)
New Revision: 14965

Modified:
   trunk/freenet/src/freenet/support/io/FileUtil.java
Log:
Doh! r14948 was a merge error; revert it.

Modified: trunk/freenet/src/freenet/support/io/FileUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileUtil.java	2007-09-04 17:31:43 UTC (rev 14964)
+++ trunk/freenet/src/freenet/support/io/FileUtil.java	2007-09-04 21:53:04 UTC (rev 14965)
@@ -12,6 +12,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 
 import freenet.client.DefaultMIMETypes;
 
@@ -24,7 +25,7 @@
 	}
 
 	/**
-	 * Guess estimate real disk usage for a file with a given filename, of a given length.
+	 * Guesstimate real disk usage for a file with a given filename, of a given length.
 	 */
 	public static long estimateUsage(File file, long flen) {
 		/**
@@ -75,24 +76,33 @@
 		return result;
 	}
 	
+	// FIXME: this is called readUTF but it reads in the default charset ... eh??
 	public static String readUTF(File file) throws FileNotFoundException, IOException {
+		StringBuffer result = new StringBuffer();
 		FileInputStream fis = null;
 		BufferedInputStream bis = null;
-		DataInputStream dis = null;
+		InputStreamReader isr = null;
 		
 		try {
 			fis = new FileInputStream(file);
 			bis = new BufferedInputStream(fis);
-			dis = new DataInputStream(bis);
+			isr = new InputStreamReader(bis);
 
-			return dis.readUTF();
+			char[] buf = new char[4096];
+			int length = 0;
+
+			while((length = isr.read(buf)) > 0) {
+				result.append(buf, 0, length);
+			}
+
 		} finally {
 			try {
-				if(dis != null) dis.close();
+				if(isr != null) isr.close();
 				if(bis != null) bis.close();
 				if(fis != null) fis.close();
 			} catch (IOException e) {}
 		}
+		return result.toString();
 	}
 	
 	public static boolean writeTo(InputStream input, File target) throws FileNotFoundException, IOException {




More information about the cvs mailing list