private static byte[] readBytesFromStream(InputStream stream, int outputLength)
      throws GeneralSecurityException {
    try {
      byte[] output = new byte[outputLength];
      int offset = 0;
      while (offset < outputLength) {
        int bytesRead = stream.read(output, offset, outputLength - offset);
        if (bytesRead <= 0) {
          throw new GeneralSecurityException(
              "Provided StreamingPrf terminated before providing requested number of bytes.");
        }
        offset += bytesRead;
      }
      return output;
    } catch (IOException exception) {
      throw new GeneralSecurityException(exception);
    }
  }
Reads the specified number of bytes from the string or throws an exception.
java_src/src/main/java/com/google/crypto/tink/subtle/prf/PrfImpl.java