You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by jeking3 <gi...@git.apache.org> on 2017/06/16 13:13:50 UTC

[GitHub] thrift pull request #705: THRIFT-3432 Add the TByteBuffer transport for Java

Github user jeking3 commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/705#discussion_r122437952
  
    --- Diff: lib/java/src/org/apache/thrift/transport/TByteBuffer.java ---
    @@ -0,0 +1,87 @@
    +package org.apache.thrift.transport;
    +
    +import java.nio.BufferOverflowException;
    +import java.nio.BufferUnderflowException;
    +import java.nio.ByteBuffer;
    +
    +/**
    + * ByteBuffer-backed implementation of TTransport.
    + */
    +public final class TByteBuffer extends TTransport {
    +  private final ByteBuffer byteBuffer;
    +
    +  /**
    +   * Creates a new TByteBuffer wrapping a given NIO ByteBuffer.
    +   */
    +  public TByteBuffer(ByteBuffer byteBuffer) {
    +    this.byteBuffer = byteBuffer;
    +  }
    +
    +  @Override
    +  public boolean isOpen() {
    +    return true;
    +  }
    +
    +  @Override
    +  public void open() {
    +  }
    +
    +  @Override
    +  public void close() {
    +  }
    +
    +  @Override
    +  public int read(byte[] buf, int off, int len) throws TTransportException {
    +    final int n = Math.min(byteBuffer.remaining(), len);
    +    if (n > 0) {
    +      try {
    +        byteBuffer.get(buf, off, len);
    --- End diff --
    
    This should have been "n" and not "len" as identified by PR #1290.  Failure of the code review system, unfortunately, and perhaps lack of a proper test for this method when the byteBuffer remaining space is smaller than the read size.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---