[
https://issues.apache.org/jira/browse/THRIFT-3432?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16051875#comment-16051875
]
ASF GitHub Bot commented on THRIFT-3432:
----------------------------------------
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.
> Add a TByteBuffer transport to the Java library
> -----------------------------------------------
>
> Key: THRIFT-3432
> URL: https://issues.apache.org/jira/browse/THRIFT-3432
> Project: Thrift
> Issue Type: Improvement
> Components: Java - Library
> Affects Versions: 0.9.3
> Reporter: Tom Lee
> Assignee: Tom Lee
> Priority: Minor
> Fix For: 0.10.0
>
>
> A bounded alternative to TMemoryBuffer that uses java.nio.ByteBuffer under
> the hood.
> This is useful both to set sane constraints on maximum message size in a
> transport-agnostic manner but also because direct buffers can be used to
> serialize Thrift off-heap, avoiding allocations (thus reducing GC frequency
> and potentially live set size)
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)