[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Don't add newline to last line when retrieving files.



commit 7a725da4969b91b6e732ecfe8ceb26f9ec9bebf9
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Jul 10 10:38:59 2013 +0200

    Don't add newline to last line when retrieving files.
---
 src/org/torproject/onionoo/DocumentStore.java |   26 ++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/org/torproject/onionoo/DocumentStore.java b/src/org/torproject/onionoo/DocumentStore.java
index 11d7d1b..e3cfc03 100644
--- a/src/org/torproject/onionoo/DocumentStore.java
+++ b/src/org/torproject/onionoo/DocumentStore.java
@@ -2,9 +2,12 @@
  * See LICENSE for licensing information */
 package org.torproject.onionoo;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -230,17 +233,22 @@ public class DocumentStore {
     }
     String documentString = null;
     try {
-      BufferedReader br = new BufferedReader(new FileReader(
-          documentFile));
-      StringBuilder sb = new StringBuilder();
-      String line;
-      while ((line = br.readLine()) != null) {
-        sb.append(line + "\n");
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      BufferedInputStream bis = new BufferedInputStream(
+          new FileInputStream(documentFile));
+      int len;
+      byte[] data = new byte[1024];
+      while ((len = bis.read(data, 0, 1024)) >= 0) {
+        baos.write(data, 0, len);
+      }
+      bis.close();
+      byte[] allData = baos.toByteArray();
+      if (allData.length == 0) {
+        return null;
       }
-      br.close();
+      documentString = new String(allData, "US-ASCII");
       this.retrievedFiles++;
-      this.retrievedBytes += sb.length();
-      documentString = sb.toString();
+      this.retrievedBytes += documentString.length();
     } catch (IOException e) {
       System.err.println("Could not read file '"
           + documentFile.getAbsolutePath() + "'.");



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits