public static void copy ( InputStream in , OutputStream out , int bufferSize , HashAssembler hashAssembler ) throws IOException { byte [ ] buffer = new byte [ bufferSize ] ; int numRead = Objects . requireNonNull ( in , "Missing input" ) . read ( buffer ) ; if ( numRead == 0 ) { throw new IllegalArgumentException ( "Missing content" ) ; } Objects . requireNonNull ( out , "Missing output" ) ; while ( numRead > 0 ) { out . write ( buffer , 0 , numRead ) ; hashAssembler . add ( buffer , numRead ) ; numRead = in . read ( buffer ) ; } }
Utility method to copy the bytes from an InputStream to an OutputStream while also assembling a hash value in the process .