Copying contents between BufferedStreams in Java This is a simple function that copies the content of one stream to another. My question is simple. I am currently, copying between the streams one byte at a time, but the streams are both Buffered. What are some ways to optimize it for speed? Any other advice would be appreciated as well.

private boolean copyToStream(BufferedInputStream inputStream, BufferedOutputStream fileStream) throws IOException {
    int byt;
    while ((byt = inputStream.read()) != -1) {
        fileStream.write(byt);
        }
    }
    return true;

}
Instead of reading the buffered stream byte-by-byte inputStream.read() you might use the advantage of buffering. This will speed up the large content copy.

private boolean copyToStream(BufferedInputStream inputStream, BufferedOutputStream fileStream) throws IOException {
    byte[] buffer = new byte[BUFFER_SIZE];
    int n;
    while ((n = inputStream.read(buffer)) != -1) {
        fileStream.write(buffer, 0, n);
    }
}


Also, consider java.nio.FileChannel transferTo() which may allow using DMA.