From 4e73d6524e8fef2024ca5bce04be138e3f1202ad Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 4 May 2011 17:05:56 +0200 Subject: [PATCH] added copy method with length to IOUtil --- .../src/main/java/sonia/scm/util/IOUtil.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) 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 9b39cfe465..c5b904bd64 100644 --- a/scm-core/src/main/java/sonia/scm/util/IOUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/IOUtil.java @@ -188,6 +188,59 @@ public class IOUtil out.flush(); } + /** + * Method description + * + * + * @param in + * @param out + * @param bufferSize + * + * @throws IOException + */ + public static void copy(InputStream in, OutputStream out, int bufferSize, int byteCount) + throws IOException + { + byte buffer[] = new byte[bufferSize]; + int len = bufferSize; + + if (byteCount >= 0) + { + while (byteCount > 0) + { + int max = (byteCount < bufferSize) + ? (int) byteCount + : bufferSize; + + len = in.read(buffer, 0, max); + + if (len == -1) + { + break; + } + + byteCount -= len; + out.write(buffer, 0, len); + } + } + else + { + while (true) + { + len = in.read(buffer, 0, bufferSize); + + if (len < 0) + { + break; + } + + out.write(buffer, 0, len); + } + } + out.flush(); + } + + /** * Method description *