Java InputStream Copy copyLarge(final InputStream input, final OutputStream output)

Here you can find the source of copyLarge(final InputStream input, final OutputStream output)

Description

copy Large

License

Apache License

Declaration

private static long copyLarge(final InputStream input, final OutputStream output) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    private static final int EOF = -1;
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

    private static long copyLarge(final InputStream input, final OutputStream output, final byte[] buffer)
            throws IOException {
        long count = 0;
        int n;//from ww w  .ja v  a2 s  .com
        while (EOF != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    private static long copyLarge(final InputStream input, final OutputStream output) throws IOException {
        return copy(input, output, DEFAULT_BUFFER_SIZE);
    }

    private static long copy(final InputStream input, final OutputStream output, final int bufferSize)
            throws IOException {
        return copyLarge(input, output, new byte[bufferSize]);
    }

    public static int copy(final InputStream input, final OutputStream output) throws IOException {
        final long count = copyLarge(input, output);
        if (count > Integer.MAX_VALUE) {
            return -1;
        }
        return (int) count;
    }
}

Related

  1. copyBytes(final InputStream in, final OutputStream out, final int buffSize, final boolean close)
  2. copyBytes(final InputStream is, final OutputStream os)
  3. copyBytes(InputStream in, OutputStream out)
  4. copyBytes(InputStream in, OutputStream out, int bufferSize, boolean close)
  5. copyBytes(InputStream in, OutputStream out, int buffSize)
  6. copyLarge(final InputStream input, final OutputStream output)
  7. copyLarge(InputStream in, OutputStream out, byte[] buffer)
  8. copyLarge(InputStream input, File outputFile)
  9. copyLarge(InputStream input, OutputStream output)