code: public long write(final InputStream in) throws IOException
  	{
  		if(in == null) throw new NullPointerException();
  		
  		final long sizeStart = size;
  		while(true) {
  			final int n = in.read(buffer, pos, buffer.length - pos);
  			if(n < 0) break;
  			pos += n;
  			size += n;
  			if(pos == buffer.length) flushBuffer();
  		}
  		return(size - sizeStart);
  	}
docs: Writes all bytes available in the given inputstream to this buffer.
  
  @param in
  @return number of bytes written
  @throws IOException