[tor-commits] [metrics-lib/master] Minor buffering improvements.

karsten at torproject.org karsten at torproject.org
Sun Jul 12 05:52:36 UTC 2015


commit 2237e8935c307e21b8f0652e65a89c63ca939991
Author: leeroy <ter.one.leeboi at hush.com>
Date:   Sat Jul 11 17:54:07 2015 -0400

    Minor buffering improvements.
---
 .../descriptor/impl/DescriptorCollectorImpl.java           |   12 +++++++-----
 .../torproject/descriptor/impl/DirectoryDownloader.java    |    4 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
index 5373b9d..8b5f2ca 100644
--- a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
@@ -2,6 +2,7 @@
  * See LICENSE for licensing information */
 package org.torproject.descriptor.impl;
 
+import java.io.BufferedOutputStream;
 import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
@@ -194,7 +195,8 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
       destinationDirectory.mkdirs();
       File tempDestinationFile = new File(destinationDirectory, "."
           + destinationFile.getName());
-      FileOutputStream fos = new FileOutputStream(tempDestinationFile);
+      BufferedOutputStream bos = new BufferedOutputStream(
+          new FileOutputStream(tempDestinationFile));
       URL u = new URL(url);
       huc = (HttpURLConnection) u.openConnection();
       huc.setRequestMethod("GET");
@@ -213,12 +215,12 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
         }
         BufferedInputStream bis = new BufferedInputStream(is);
         int len;
-        byte[] data = new byte[1024];
-        while ((len = bis.read(data, 0, 1024)) >= 0) {
-          fos.write(data, 0, len);
+        byte[] data = new byte[8192];
+        while ((len = bis.read(data, 0, 8192)) >= 0) {
+          bos.write(data, 0, len);
         }
         bis.close();
-        fos.close();
+        bos.close();
         tempDestinationFile.renameTo(destinationFile);
         destinationFile.setLastModified(lastModifiedMillis);
       }
diff --git a/src/org/torproject/descriptor/impl/DirectoryDownloader.java b/src/org/torproject/descriptor/impl/DirectoryDownloader.java
index 4266217..66af559 100644
--- a/src/org/torproject/descriptor/impl/DirectoryDownloader.java
+++ b/src/org/torproject/descriptor/impl/DirectoryDownloader.java
@@ -73,8 +73,8 @@ public class DirectoryDownloader implements Runnable {
                 new InflaterInputStream(huc.getInputStream()));
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             int len;
-            byte[] data = new byte[1024];
-            while ((len = in.read(data, 0, 1024)) >= 0) {
+            byte[] data = new byte[8192];
+            while ((len = in.read(data, 0, 8192)) >= 0) {
               baos.write(data, 0, len);
             }
             in.close();



More information about the tor-commits mailing list