mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 15:02:17 +01:00
added copy method with length to IOUtil
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user