public static byte[] convertInputStreamToByteArray(InputStream inputStream,int inputStreamLength) throws IOException {
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  int blockSize=DEFAULT_BUFFER_SIZE;
  byte[] buffer=new byte[blockSize];
  int left=inputStreamLength;
  while (left > 0) {
    int read=inputStream.read(buffer,0,left > blockSize ? blockSize : left);
    if (read == -1)     break;
    out.write(buffer,0,read);
    left-=read;
  }
  return out.toByteArray();
}

public static byte [ ] convertInputStreamToByteArray ( InputStream inputStream , int inputStreamLength ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; int blockSize = DEFAULT_BUFFER_SIZE ; byte [ ] buffer = new byte [ blockSize ] ; int left = inputStreamLength ; while ( left > 0 ) { int read = inputStream . read ( buffer , 0 , left > blockSize ? blockSize : left ) ; if ( read == - 1 ) break ; out . write ( buffer , 0 , read ) ; left -= read ; } return out . toByteArray ( ) ; }
converts an input stream to a byte array
