Java InputStream Copy copyLarge(InputStream input, OutputStream output)

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

Description

copy Large

License

LGPL

Parameter

Parameter Description
input the <code>InputStream</code> to read from
output the <code>OutputStream</code> to write to

Exception

Parameter Description
NullPointerException if the input or output is null
IOExceptionif an I/O error occurs

Return

the number of bytes copied

Declaration

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

Method Source Code

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

import java.io.*;

public class Main {
    /**//from  www.  ja v  a2s.c  o m
     * default buffer size
     */
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
    /**
     * End of File
     */
    private static final int EOF = -1;

    /**
     * @param input  the <code>InputStream</code> to read from
     * @param output the <code>OutputStream</code> to write to
     * @return the number of bytes copied
     * @throws NullPointerException if the input or output is null
     * @throws IOException          if an I/O error occurs
     */
    public static long copyLarge(InputStream input, OutputStream output)
            throws IOException {
        return copyLarge(input, output, new byte[DEFAULT_BUFFER_SIZE]);
    }

    /**
     * @param input  the <code>InputStream</code> to read from
     * @param output the <code>OutputStream</code> to write to
     * @return the number of bytes copied
     * @throws NullPointerException if the input or output is null
     * @throws 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. copyBytes(InputStream in, OutputStream out, int buffSize)
  2. copyLarge(final InputStream input, final OutputStream output)
  3. copyLarge(final InputStream input, final OutputStream output)
  4. copyLarge(InputStream in, OutputStream out, byte[] buffer)
  5. copyLarge(InputStream input, File outputFile)
  6. copyLarge(InputStream input, OutputStream output)
  7. copyLarge(InputStream input, OutputStream output)
  8. copyLarge(InputStream input, OutputStream output)
  9. copyLarge(InputStream input, OutputStream output)