nl_tokens: Reads data from an input stream and writes it to an output stream calculates the length of the data written and optionally calculates the MD5 hash for the data .
pl_tokens: public static StreamMd5AndLength writeToOutputStream ( final InputStream sourceStream , final OutputStream outStream , long writeLength , final boolean rewindSourceStream , final boolean calculateMD5 , OperationContext opContext , final RequestOptions options , StorageRequest < ? , ? , Integer > request , StreamMd5AndLength descriptor ) throws IOException , StorageException { if ( rewindSourceStream && sourceStream . markSupported ( ) ) { sourceStream . reset ( ) ; sourceStream . mark ( Constants . MAX_MARK_LENGTH ) ; } if ( descriptor == null ) { descriptor = new StreamMd5AndLength ( ) ; if ( calculateMD5 ) { try { descriptor . setDigest ( MessageDigest . getInstance ( "MD5" ) ) ; } catch ( final NoSuchAlgorithmException e ) { // This wont happen, throw fatal. throw Utility . generateNewUnexpectedStorageException ( e ) ; } } } else { descriptor . setMd5 ( null ) ; } if ( writeLength < 0 ) { writeLength = Long . MAX_VALUE ; } final byte [ ] retrievedBuff = new byte [ Constants . BUFFER_COPY_LENGTH ] ; int nextCopy = ( int ) Math . <mask> ( retrievedBuff . length , writeLength ) ; int count = sourceStream . read ( retrievedBuff , 0 , nextCopy ) ; while ( nextCopy > 0 && count != - 1 ) { // if maximum execution time would be exceeded if ( Utility . validateMaxExecutionTimeout ( options . getOperationExpiryTimeInMs ( ) ) ) { // throw an exception TimeoutException timeoutException = new TimeoutException ( SR . MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION ) ; throw Utility . initIOException ( timeoutException ) ; } if ( outStream != null ) { outStream . write ( retrievedBuff , 0 , count ) ; } if ( calculateMD5 ) { descriptor . getDigest ( ) . update ( retrievedBuff , 0 , count ) ; } descriptor . setLength ( descriptor . getLength ( ) + count ) ; descriptor . setCurrentOperationByteCount ( descriptor . getCurrentOperationByteCount ( ) + count ) ; if ( request != null ) { request . setCurrentRequestByteCount ( request . getCurrentRequestByteCount ( ) + count ) ; request . setCurrentDescriptor ( descriptor ) ; } nextCopy = ( int ) Math . min ( retrievedBuff . length , writeLength - descriptor . getLength ( ) ) ; count = sourceStream . read ( retrievedBuff , 0 , nextCopy ) ; } if ( outStream != null ) { outStream . flush ( ) ; } return descriptor ; }