Ticket #16557: 0001-Minor-buffering-improvements.patch

File 0001-Minor-buffering-improvements.patch, 2.9 KB (added by leeroy, 4 years ago)
  • src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java

    From 77bbd36670f5454868c5a4edb715773ecf483887 Mon Sep 17 00:00:00 2001
    From: leeroy <ter.one.leeboi@hush.com>
    Date: Sat, 11 Jul 2015 17:54:07 -0400
    Subject: [PATCH 1/1] Minor buffering improvements.
    
    ---
     .../torproject/descriptor/impl/DescriptorCollectorImpl.java  | 12 +++++++-----
     src/org/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..c088c00 100644
    a b  
    22 * See LICENSE for licensing information */
    33package org.torproject.descriptor.impl;
    44
     5import java.io.BufferedOutputStream;
    56import java.io.BufferedInputStream;
    67import java.io.BufferedReader;
    78import java.io.File;
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    194195      destinationDirectory.mkdirs();
    195196      File tempDestinationFile = new File(destinationDirectory, "."
    196197          + destinationFile.getName());
    197       FileOutputStream fos = new FileOutputStream(tempDestinationFile);
     198      BufferedOutputStream bos = new BufferedOutputStream(
     199        new FileOutputStream(tempDestinationFile));
    198200      URL u = new URL(url);
    199201      huc = (HttpURLConnection) u.openConnection();
    200202      huc.setRequestMethod("GET");
    public class DescriptorCollectorImpl implements DescriptorCollector { 
    213215        }
    214216        BufferedInputStream bis = new BufferedInputStream(is);
    215217        int len;
    216         byte[] data = new byte[1024];
    217         while ((len = bis.read(data, 0, 1024)) >= 0) {
    218           fos.write(data, 0, len);
     218        byte[] data = new byte[8192];
     219        while ((len = bis.read(data, 0, 8192)) >= 0) {
     220          bos.write(data, 0, len);
    219221        }
    220222        bis.close();
    221         fos.close();
     223        bos.close();
    222224        tempDestinationFile.renameTo(destinationFile);
    223225        destinationFile.setLastModified(lastModifiedMillis);
    224226      }
  • src/org/torproject/descriptor/impl/DirectoryDownloader.java

    diff --git a/src/org/torproject/descriptor/impl/DirectoryDownloader.java b/src/org/torproject/descriptor/impl/DirectoryDownloader.java
    index 4266217..66af559 100644
    a b public class DirectoryDownloader implements Runnable { 
    7373                new InflaterInputStream(huc.getInputStream()));
    7474            ByteArrayOutputStream baos = new ByteArrayOutputStream();
    7575            int len;
    76             byte[] data = new byte[1024];
    77             while ((len = in.read(data, 0, 1024)) >= 0) {
     76            byte[] data = new byte[8192];
     77            while ((len = in.read(data, 0, 8192)) >= 0) {
    7878              baos.write(data, 0, len);
    7979            }
    8080            in.close();