public void add ( byte [ ] bytes , int offset , int length ) throws IllegalArgumentException , BufferSizeException { // validate the bytes, offset, length checkOffsetLength ( bytes . length , offset , length ) ; // is there enough free space in this buffer to add the entire array if ( length > free ( ) ) { throw new BufferSizeException ( "Buffer does not have enough free space (" + free ( ) + " bytes) to add " + length + " bytes of data" ) ; } // add each byte to this array for ( int i = 0 ; i < length ; i ++ ) { try { this . add ( bytes [ i + offset ] ) ; } catch ( BufferIsFullException e ) { // this should be an impossible case since we checked the size() above logger . error ( "Buffer is full even though this method checked its size() ahead of time" , e ) ; throw new BufferSizeException ( e . getMessage ( ) ) ; } } }
Adds a byte array to this buffer starting from the offset up to the length requested . If the free space remaining in the buffer is not large enough this method will throw a BufferSizeException .