@Override
    public synchronized int read(ByteBuffer dst) throws IOException {
      checkIsOpen();
      if (this.noDataEveryOtherRead) {
        boolean returnData = this.returnDataOnNextRead;
        this.returnDataOnNextRead = !this.returnDataOnNextRead;
        if (!returnData) {
          return 0;
        }
      }
      if (buffer.remaining() == 0) {
        return -1;
      }
      // Not the most efficient way.
      int size = Math.min(buffer.remaining(), dst.remaining());
      size = Math.min(size, maxChunkSize);
      byte[] bytes = new byte[size];
      buffer.get(bytes);
      dst.put(bytes);
      return size;
    }
keeps track whether the channel is still open.
java_src/src/main/java/com/google/crypto/tink/testing/StreamingTestUtil.java