public static byte[] readFully(InputStream in) throws IOException {
  byte[] buffer=new byte[1024];
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  while (true) {
    int byteCount=in.read(buffer);
    if (byteCount == -1) {
      return bytes.toByteArray();
    }
    bytes.write(buffer,0,byteCount);
  }
}

public static byte [ ] readFully ( InputStream in ) throws IOException { byte [ ] buffer = new byte [ 1024 ] ; ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ; while ( true ) { int byteCount = in . read ( buffer ) ; if ( byteCount == - 1 ) { return bytes . toByteArray ( ) ; } bytes . write ( buffer , 0 , byteCount ) ; } }
fully read the contents of the given stream .
