code: public static byte[] loadFromStream(InputStream stream) {
  		try {
  			BufferedInputStream bis = new BufferedInputStream(stream);
  			int size = 2048;
  			byte[] theData = new byte[size];
  			int dataReadSoFar = 0;
  			byte[] buffer = new byte[size / 2];
  			int read = 0;
  			while ((read = bis.read(buffer)) != -1) {
  				if ((read + dataReadSoFar) > theData.length) {
  					// need to make more room
  					byte[] newTheData = new byte[theData.length * 2];
  					// System.out.println("doubled to " + newTheData.length);
  					System.arraycopy(theData, 0, newTheData, 0, dataReadSoFar);
  					theData = newTheData;
  				}
  				System.arraycopy(buffer, 0, theData, dataReadSoFar, read);
  				dataReadSoFar += read;
  			}
  			bis.close();
  			// Resize to actual data read
  			byte[] returnData = new byte[dataReadSoFar];
  			System.arraycopy(theData, 0, returnData, 0, dataReadSoFar);
  			return returnData;
  		}
  		catch (IOException e) {
  			throw new ReloadException("Unexpectedly unable to load bytedata from input stream", e);
  		}
  	}
docs: Load the contents of an input stream.
  
  @param stream input stream that contains the bytes to load
  @return the byte array loaded from the input stream