Java InputStream Copy copyLarge(InputStream input, OutputStream output, byte[] buffer)

Here you can find the source of copyLarge(InputStream input, OutputStream output, byte[] buffer)

Description

Copy bytes from a large (over 2GB) InputStream to an OutputStream.

License

Apache License

Parameter

Parameter Description
input the <code>InputStream</code> to read from
output the <code>OutputStream</code> to write to
buffer the buffer to use for the copy

Exception

Parameter Description
NullPointerException if the input or output is null

Return

the number of bytes copied

Declaration

public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) 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;

    /**// w w  w  .  j a va 2 s. c om
     * Copy bytes from a large (over 2GB) <code>InputStream</code> to an <code>OutputStream</code>.
     * <p>
     * This method uses the provided buffer, so there is no need to use a
     * <code>BufferedInputStream</code>.
     * <p>
     *
     * @param input  the <code>InputStream</code> to read from
     * @param output the <code>OutputStream</code> to write to
     * @param buffer the buffer to use for the copy
     * @return the number of bytes copied
     * @throws NullPointerException if the input or output is null
     * @throws java.io.IOException  if an I/O error occurs
     */
    public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
        long count = 0;
        int n = 0;
        while (EOF != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }
}

Related

  1. copyLarge(InputStream input, OutputStream output)
  2. copyLarge(InputStream input, OutputStream output)
  3. copyLarge(InputStream input, OutputStream output)
  4. copyLarge(InputStream input, OutputStream output)
  5. copyLarge(InputStream input, OutputStream output, byte[] buffer)
  6. copyLarge(InputStream input, OutputStream output, byte[] buffer)
  7. copyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
  8. copyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
  9. copyLarge(InputStream input, OutputStream output, long limit)