private static void encryptWithChannel(
      StreamingAead ags,
      ReadableByteChannel plaintext,
      WritableByteChannel ciphertext,
      byte[] associatedData,
      int chunkSize) {
    try (WritableByteChannel encChannel = ags.newEncryptingChannel(ciphertext, associatedData)) {
      ByteBuffer chunk = ByteBuffer.allocate(chunkSize);
      int read;
      do {
        chunk.clear();
        read = plaintext.read(chunk);
        if (read > 0) {
          chunk.flip();
          encChannel.write(chunk);
        }
      } while (read != -1);
    } catch (Exception ex) {
      // TODO(bleichen): What is the best way to chatch exceptions in threads?
      throw new RuntimeException(ex);
    }
  }
Reads everything from plaintext, encrypt it and writes the result to ciphertext. This method is
used to test aynchronous encryption.

@param ags the streaming encryption
@param plaintext the channel containing the plaintext
@param ciphertext the channel to which the ciphertext is written
@param associatedData the additional data to authenticate
@param chunkSize the size of blocks that are read and written. This size determines the
    temporary memory used in this method but is independent of the streaming encryption.
@throws RuntimeException if something goes wrong.
java_src/src/main/java/com/google/crypto/tink/testing/StreamingTestUtil.java