From 7119afb5bc66ab0a2167cd9e4c92b9445c6343e0 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 15 Apr 2011 18:36:16 +0200 Subject: [PATCH] added bufferSize to copyThread methods --- .../src/main/java/sonia/scm/util/IOUtil.java | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/util/IOUtil.java b/scm-core/src/main/java/sonia/scm/util/IOUtil.java index d7cca44d7c..04455f59e5 100644 --- a/scm-core/src/main/java/sonia/scm/util/IOUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/IOUtil.java @@ -65,6 +65,9 @@ import java.util.List; public class IOUtil { + /** Field description */ + public static final int DEFAULT_BUFFERSIZE = 8192; + /** Field description */ private static final String DEFAULT_CHECKPARAMETER = "--version"; @@ -144,7 +147,7 @@ public class IOUtil */ public static void copy(Reader reader, Writer writer) throws IOException { - copy(reader, writer, 0xFFFF); + copy(reader, writer, DEFAULT_BUFFERSIZE); } /** @@ -158,7 +161,7 @@ public class IOUtil */ public static void copy(InputStream in, OutputStream out) throws IOException { - copy(in, out, 0xFFFF); + copy(in, out, DEFAULT_BUFFERSIZE); } /** @@ -237,7 +240,7 @@ public class IOUtil */ public static void copyThread(Reader reader, Writer writer) { - new Thread(new IOCopyThread(reader, writer)).start(); + copyThread(reader, writer, DEFAULT_BUFFERSIZE); } /** @@ -249,7 +252,34 @@ public class IOUtil */ public static void copyThread(InputStream input, OutputStream output) { - new Thread(new IOStreamCopyThread(input, output)).start(); + copyThread(input, output, DEFAULT_BUFFERSIZE); + } + + /** + * Method description + * + * + * @param reader + * @param writer + * @param bufferSize + */ + public static void copyThread(Reader reader, Writer writer, int bufferSize) + { + new Thread(new IOCopyThread(reader, writer, bufferSize)).start(); + } + + /** + * Method description + * + * + * @param input + * @param output + * @param bufferSize + */ + public static void copyThread(InputStream input, OutputStream output, + int bufferSize) + { + new Thread(new IOStreamCopyThread(input, output, bufferSize)).start(); } /** @@ -482,11 +512,13 @@ public class IOUtil * * @param reader * @param writer + * @param bufferSize */ - public IOCopyThread(Reader reader, Writer writer) + public IOCopyThread(Reader reader, Writer writer, int bufferSize) { this.reader = reader; this.writer = writer; + this.bufferSize = bufferSize; } //~--- methods ------------------------------------------------------------ @@ -500,7 +532,7 @@ public class IOUtil { try { - copy(reader, writer); + copy(reader, writer, bufferSize); } catch (IOException ex) { @@ -515,6 +547,9 @@ public class IOUtil //~--- fields ------------------------------------------------------------- + /** Field description */ + private int bufferSize; + /** Field description */ private Reader reader; @@ -539,11 +574,14 @@ public class IOUtil * * @param input * @param output + * @param bufferSize */ - public IOStreamCopyThread(InputStream input, OutputStream output) + public IOStreamCopyThread(InputStream input, OutputStream output, + int bufferSize) { this.input = input; this.output = output; + this.bufferSize = bufferSize; } //~--- methods ------------------------------------------------------------ @@ -557,7 +595,7 @@ public class IOUtil { try { - copy(input, output); + copy(input, output, bufferSize); } catch (IOException ex) { @@ -572,6 +610,9 @@ public class IOUtil //~--- fields ------------------------------------------------------------- + /** Field description */ + private int bufferSize; + /** Field description */ private InputStream input;