Java Utililty Methods InputStream Copy nio

List of utility methods to do InputStream Copy nio

Description

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

Method

voidcopy(InputStream in, File f, long startAt)
copy
copy(in, new FileOutputStream(f), startAt, true, true);
voidcopy(InputStream in, OutputStream out)
copy
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
while ((read = in.read(b)) != -1) {
    out.write(b, 0, read);
longcopy(InputStream in, OutputStream out)
Copies the content of the InputStream to the OutputStream.
long filesize = 0;
try {
    byte[] buffer = new byte[BUFF_SIZE];
    int bytesRead = in.read(buffer);
    while (bytesRead != -1) {
        filesize += bytesRead;
        out.write(buffer, 0, bytesRead);
        bytesRead = in.read(buffer);
...
voidcopy(InputStream in, OutputStream out)
Verbatim copy an entry from input to output stream.
copy(in, out, 512 * 1024);
intcopy(InputStream in, OutputStream out)
copy
try {
    int byteCount = 0;
    byte[] buffer = new byte[BUFFER_SIZE];
    int bytesRead = -1;
    while ((bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
        byteCount += bytesRead;
    out.flush();
    return byteCount;
} finally {
    try {
        in.close();
    } catch (IOException ex) {
    try {
        out.close();
    } catch (IOException ex) {
longcopy(InputStream in, OutputStream out)
copy the in to out
byte[] buf = new byte[1024 * 64];
long total = 0;
int size = 0;
while ((size = in.read(buf)) != -1) {
    out.write(buf, 0, size);
    total += size;
return total;
...
voidcopy(InputStream in, OutputStream out, boolean closeInput, boolean closeOutput)
copy
byte[] buffer = new byte[BUFFER_SIZE];
int len;
try {
    while ((len = in.read(buffer)) != -1) {
        out.write(buffer, 0, len);
} finally {
    Throwable t = null;
...
longcopy(InputStream input, OutputStream output)
Copies all data from an InputStream to an OutputStream.
byte[] buffer = new byte[2 * 1024];
long total = 0;
int count;
while ((count = input.read(buffer)) != -1) {
    output.write(buffer, 0, count);
    total += count;
return total;
...
longcopy(InputStream input, OutputStream output)
copy
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
long count = 0L;
int n = 0;
while (-1 != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
return count;
...
voidcopy(InputStream input, OutputStream output)
copy
if ((output instanceof FileOutputStream) && (input instanceof FileInputStream)) {
    try {
        FileChannel target = ((FileOutputStream) output).getChannel();
        FileChannel source = ((FileInputStream) input).getChannel();
        source.transferTo(0, Integer.MAX_VALUE, target);
        source.close();
        target.close();
        return;
...