public void testDecryption(StreamingAead stream, byte[] associatedData, int chunkSize)
      throws Exception {
    int numberOfThreads = 10;
    int plaintextSize = 5432; // The plaintext size for each thread.
    byte[] ciphertext = encrypt(stream, new byte[numberOfThreads * plaintextSize], associatedData);
    SeekableByteChannel ctChannel = new SeekableByteBufferChannel(ciphertext);
    SeekableByteChannel decChannel = stream.newSeekableDecryptingChannel(ctChannel, associatedData);

    ExceptionHandler exceptionHandler = new ExceptionHandler();
    Thread[] thread = new Thread[numberOfThreads];
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i] = new DecryptingThread(decChannel, plaintextSize, chunkSize);
      thread[i].setUncaughtExceptionHandler(exceptionHandler);
    }
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i].start();
    }
    for (int i = 0; i < numberOfThreads; i++) {
      thread[i].join();
    }
    exceptionHandler.check();

    // Each thread has read plaintextSize bytes from decChannel. Hence nothing should be left.
    int read = decChannel.read(ByteBuffer.allocate(1));
    assertEquals(-1, read);
  }
Test for thread safety. This test is an incorrect use case for StreamingAead implementations.
Streams have state and hence their behaviour is not well defined. Nevertheless if an encrypting
channel is used concurrently we expect the following behaviour: (1) All bytes are read (2) The
thread sanitizer does not find anything.
java_src/src/test/java/com/google/crypto/tink/subtle/StreamingAeadThreadSafetyTest.java