@Override
  public synchronized void close() throws IOException {
    if (!open) {
      return;
    }
    try {
      ptBuffer.flip();
      ctBuffer.clear();
      encrypter.encryptSegment(ptBuffer, true, ctBuffer);
    } catch (GeneralSecurityException ex) {
      // TODO(bleichen): define the state of this. E.g. open = false;
      throw new IOException(
          "ptBuffer.remaining():"
              + ptBuffer.remaining()
              + " ctBuffer.remaining():"
              + ctBuffer.remaining(),
          ex);
    }
    ctBuffer.flip();
    out.write(ctBuffer.array(), ctBuffer.position(), ctBuffer.remaining());
    open = false;
    super.close();
  }
An instance of {@link FilterOutputStream} that encrypts the input using a nonce based online
authentication scheme.
java_src/src/main/java/com/google/crypto/tink/subtle/StreamingAeadEncryptingStream.java