@Theory
  public void readKeyset_encryptDecrypt_success() throws Exception {
    KeysetHandle handle =
        TinkJsonProtoKeysetFormat.parseKeyset(
            JSON_STREAMING_AEAD_KEYSET, InsecureSecretKeyAccess.get());
    StreamingAead streamingAead = handle.getPrimitive(StreamingAead.class);

    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);

    ByteArrayOutputStream ciphertextOutputStream = new ByteArrayOutputStream();
    try (WritableByteChannel encryptingChannel =
        streamingAead.newEncryptingChannel(
            Channels.newChannel(ciphertextOutputStream), associatedData)) {
      writeToChannel(encryptingChannel, plaintext);
    }
    byte[] ciphertext = ciphertextOutputStream.toByteArray();

    byte[] decrypted = null;
    ReadableByteChannel ciphertextSource =
        Channels.newChannel(new ByteArrayInputStream(ciphertext));
    try (ReadableByteChannel decryptingChannel =
        streamingAead.newDecryptingChannel(ciphertextSource, associatedData)) {
      decrypted = readFromChannel(decryptingChannel, plaintext.length);
    }
    assertThat(decrypted).isEqualTo(plaintext);
  }
Reads {@code bytesToRead} bytes from {@code readableChannel}.
java_src/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadTest.java