public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[BUFFER_SIZE];
        while (true) {
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            out.write(buffer, 0, read);
            byteCount += read;
        }
        return byteCount;
    }
public static int copyAllBytes ( InputStream in , OutputStream out ) throws IOException { int byteCount = 0 ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; while ( true ) { int read = in . read ( buffer ) ; if ( read == - 1 ) { break ; } out . write ( buffer , 0 , read ) ; byteCount += read ; } return byteCount ; }
Copies all available data from in to out without closing any stream.

@return number of bytes copied