Java Utililty Methods InputStream Copy

List of utility methods to do InputStream Copy

Description

The list of methods to do InputStream Copy are organized into topic(s).

Method

longcopyLarge(InputStream input, OutputStream output, byte[] buffer)
copy Large
long count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
return count;
longcopyLarge(InputStream input, OutputStream output, byte[] buffer)
Copy bytes from a large (over 2GB) InputStream to an OutputStream.
long count = 0;
int n = 0;
while (EOF != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
return count;
longcopyLarge(InputStream input, OutputStream output, byte[] buffer)
copy Large
long count = 0;
int n;
while (EOF != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
return count;
longcopyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
Copy some or all bytes from a large (over 2GB) InputStream to an OutputStream, optionally skipping input bytes.
if (inputOffset > 0) {
    skipFully(input, inputOffset);
if (length == 0) {
    return 0;
final int bufferLength = buffer.length;
int bytesToRead = bufferLength;
...
longcopyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
Copy some or all bytes from a large (over 2GB) InputStream to an OutputStream, optionally skipping input bytes.
if (inputOffset > 0) {
    skipFully(input, inputOffset);
if (length == 0) {
    return 0;
final int bufferLength = buffer.length;
int bytesToRead = bufferLength;
...
longcopyLarge(InputStream input, OutputStream output, long limit)
copy Large
return copyLargeLimited(input, output, limit);
voidcopyStream(final BufferedReader in, final PrintWriter out, final String[] mapFrom, String[] mapTo)
copy Stream
String line;
while ((line = in.readLine()) != null) {
    for (int i = 0; i < mapFrom.length; i++) {
        line = line.replaceAll(mapFrom[i], mapTo[i]);
    out.println(line);
InputStreamcopyStream(InputStream is)
copy Stream
byte[] entity = new byte[4096];
int entitySize = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((entitySize = is.read(entity)) != -1)
    baos.write(entity, 0, entitySize);
InputStream cpis = new ByteArrayInputStream(baos.toByteArray());
baos.close();
return cpis;
...
byte[]copyStream(InputStream is)
copy Stream
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[64 * 1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
    buffer.write(data, 0, nRead);
buffer.flush();
return buffer.toByteArray();
...
byte[]copyStream(InputStream iss)
Read a stream fully to an in-memory byte array.
ByteArrayOutputStream baosExp = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int read;
do {
    read = iss.read(buffer, 0, buffer.length);
    if (read > 0) {
        baosExp.write(buffer, 0, read);
} while (read >= 0);
baosExp.close();
return baosExp.toByteArray();