public ByteBuffer(InputStream in) throws IOException {
  int chunk=16384;
  this.length=0;
  this.buffer=new byte[chunk];
  int read;
  while ((read=in.read(this.buffer,this.length,chunk)) > 0) {
    this.length+=read;
    if (read == chunk) {
      ensureCapacity(length + chunk);
    }
 else {
      break;
    }
  }
}

public ByteBuffer ( InputStream in ) throws IOException { int chunk = 16384 ; this . length = 0 ; this . buffer = new byte [ chunk ] ; int read ; while ( ( read = in . read ( this . buffer , this . length , chunk ) ) > 0 ) { this . length += read ; if ( read == chunk ) { ensureCapacity ( length + chunk ) ; } else { break ; } } }
loads the stream into a buffer .
