private static byte[] encryptWithStream(
      StreamingAead ags, byte[] plaintext, byte[] associatedData, int firstSegmentOffset)
      throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write(new byte[firstSegmentOffset]);
    try (OutputStream encChannel = ags.newEncryptingStream(bos, associatedData)) {
      encChannel.write(plaintext);
    }
    byte[] ciphertext = bos.toByteArray();
    return ciphertext;
  }
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