public static byte[] slurp(InputStream in) throws IOException {
  if (in == null)   throw new NullPointerException("`in' must not be null");
  try {
    int nRead;
    byte[] buffer=new byte[1024];
    ByteArrayOutputStream out=new ByteArrayOutputStream();
    while ((nRead=in.read(buffer,0,buffer.length)) != -1) {
      out.write(buffer,0,nRead);
    }
    return out.toByteArray();
  }
  finally {
    in.close();
  }
}

public static byte [ ] slurp ( InputStream in ) throws IOException { if ( in == null ) throw new NullPointerException ( "`in' must not be null" ) ; try { int nRead ; byte [ ] buffer = new byte [ 1024 ] ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; while ( ( nRead = in . read ( buffer , 0 , buffer . length ) ) != - 1 ) { out . write ( buffer , 0 , nRead ) ; } return out . toByteArray ( ) ; } finally { in . close ( ) ; } }
fully consume an inputstream into a byte array , and close the input .
