public int copyMax ( final OutputStream out , final int maxBytes ) throws IOException { int count = 0 ; while ( true ) { byte b = readByte ( ) ; if ( isBoundary ( b ) ) { break ; } out . write ( b ) ; count ++ ; if ( count == maxBytes ) { return count ; } } return count ; }
Copies max or less number of bytes to output stream . Useful for determining if uploaded file is larger then expected .