added copy method with length to IOUtil

This commit is contained in:
Sebastian Sdorra
2011-05-04 17:05:56 +02:00
parent ff7e01a4dc
commit 4e73d6524e

View File

@@ -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
*