public void append(byte[] bytes,int offset,int length){
  while (length > 0) {
    int freeSpaceInEndChunk=mChunks.size() * mChunkSize - mSize;
    int positionInEndChunk=mChunkSize - freeSpaceInEndChunk;
    if (freeSpaceInEndChunk == 0) {
      mChunks.add(new byte[mChunkSize]);
      freeSpaceInEndChunk=mChunkSize;
      positionInEndChunk=0;
    }
    byte[] endChunk=mChunks.get(mChunks.size() - 1);
    if (length > freeSpaceInEndChunk) {
      System.arraycopy(bytes,offset,endChunk,positionInEndChunk,freeSpaceInEndChunk);
      mSize+=freeSpaceInEndChunk;
      offset+=freeSpaceInEndChunk;
      length-=freeSpaceInEndChunk;
    }
 else {
      System.arraycopy(bytes,offset,endChunk,positionInEndChunk,length);
      mSize+=length;
      offset+=length;
      length=0;
    }
  }
}

public void append ( byte [ ] bytes , int offset , int length ) { while ( length > 0 ) { int freeSpaceInEndChunk = mChunks . size ( ) * mChunkSize - mSize ; int positionInEndChunk = mChunkSize - freeSpaceInEndChunk ; if ( freeSpaceInEndChunk == 0 ) { mChunks . add ( new byte [ mChunkSize ] ) ; freeSpaceInEndChunk = mChunkSize ; positionInEndChunk = 0 ; } byte [ ] endChunk = mChunks . get ( mChunks . size ( ) - 1 ) ; if ( length > freeSpaceInEndChunk ) { System . arraycopy ( bytes , offset , endChunk , positionInEndChunk , freeSpaceInEndChunk ) ; mSize += freeSpaceInEndChunk ; offset += freeSpaceInEndChunk ; length -= freeSpaceInEndChunk ; } else { System . arraycopy ( bytes , offset , endChunk , positionInEndChunk , length ) ; mSize += length ; offset += length ; length = 0 ; } } }
adds bytes to the buffer
