public static byte[] streamToBytes(InputStream in,int length,ByteArrayPool pool) throws IOException {
  byte[] bytes;
  if (pool == null)   bytes=new byte[length];
 else   bytes=pool.getBuf(length);
  int count;
  int pos=0;
  while (pos < length && ((count=in.read(bytes,pos,length - pos)) != -1)) {
    pos+=count;
  }
  if (pos != length) {
    throw new IOException("Expected " + length + " bytes, read "+ pos+ " bytes");
  }
  return bytes;
}

public static byte [ ] streamToBytes ( InputStream in , int length , ByteArrayPool pool ) throws IOException { byte [ ] bytes ; if ( pool == null ) bytes = new byte [ length ] ; else bytes = pool . getBuf ( length ) ; int count ; int pos = 0 ; while ( pos < length && ( ( count = in . read ( bytes , pos , length - pos ) ) != - 1 ) ) { pos += count ; } if ( pos != length ) { throw new IOException ( "Expected " + length + " bytes, read " + pos + " bytes" ) ; } return bytes ; }
reads the contents of an inputstream into a byte [ ] .
