private void readHeader() throws IOException {
    if (headerRead) {
      setDecryptionErrorOccured();
      throw new IOException("Decryption failed.");
    }
    ByteBuffer header = ByteBuffer.allocate(headerLength);
    while (header.remaining() > 0) {
      int read = in.read(header.array(), header.position(), header.remaining());
      if (read == -1) {
        setDecryptionErrorOccured();
        throw new IOException("Ciphertext is too short");
      }
      if (read == 0) {
        throw new IOException("Could not read bytes from the ciphertext stream");
      }
      header.position(header.position() + read);
    }
    header.flip();
    try {
      decrypter.init(header, aad);
    } catch (GeneralSecurityException ex) {
      throw new IOException(ex);
    }
    headerRead = true;
  }
Reads the header of the ciphertext and sets headerRead = true.

@throws IOException when an exception occurs while reading from {@code in} or when the header
    is too short.
java_src/src/main/java/com/google/crypto/tink/subtle/StreamingAeadDecryptingStream.java