All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.xpipe.core.util.StreamHelper Maven / Gradle / Ivy

package io.xpipe.core.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Objects;

public class StreamHelper {

    private static final int DEFAULT_BUFFER_SIZE = 8192;

    public static long transferTo(InputStream in, OutputStream out) throws IOException {
        Objects.requireNonNull(out, "out");
        long transferred = 0;
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int read;
        while (in.available() > 0 && (read = in.read(buffer, 0, DEFAULT_BUFFER_SIZE)) >= 0) {
            out.write(buffer, 0, read);
            transferred += read;
        }
        return transferred;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy