@Override public void consumeBuffer(int len) { readBuffer.consumeBuffer(len); }
@Override public byte[] getBuffer() { return readBuffer.getBuffer(); }
@Override public int getBufferPosition() { return readBuffer.getBufferPosition(); }
@Override public final int read(byte[] target, int off, int len) throws TTransportException { int amtToRead = Math.min(len, getBytesRemainingInBuffer()); System.arraycopy(buf.array(), pos, target, off, amtToRead); consumeBuffer(amtToRead); return amtToRead; }
private void readFrame() throws TTransportException { underlying.readAll(i32buf , 0, 4); int size = TFramedTransport.decodeFrameSize(i32buf); if (size < 0) { throw new TTransportException("Read a negative frame size (" + size + ")!"); } if (size > maxLength) { throw new TTransportException("Frame size (" + size + ") larger than max length (" + maxLength + ")!"); } readBuffer.fill(underlying, size); }
@Override public int getBytesRemainingInBuffer() { return readBuffer.getBytesRemainingInBuffer(); } }
/** * * @param underlying Transport that real reads and writes will go through to. * @param initialBufferCapacity The initial size of the read and write buffers. * In practice, it's not critical to set this unless you know in advance that * your messages are going to be very large. (You can pass * TFramedTransportWithReusableBuffer.DEFAULT_BUF_CAPACITY if you're only * using this constructor because you want to set the maxLength.) * @param maxLength The max frame size you are willing to read. You can use * this parameter to limit how much memory can be allocated. */ public TFastFramedTransport(TTransport underlying, int initialBufferCapacity, int maxLength) { this.underlying = underlying; this.maxLength = maxLength; writeBuffer = new AutoExpandingBufferWriteTransport(initialBufferCapacity, 1.5); readBuffer = new AutoExpandingBufferReadTransport(initialBufferCapacity, 1.5); }
@Override public final int read(byte[] target, int off, int len) throws TTransportException { int amtToRead = Math.min(len, getBytesRemainingInBuffer()); System.arraycopy(buf.array(), pos, target, off, amtToRead); consumeBuffer(amtToRead); return amtToRead; }
private void readFrame() throws TTransportException { underlying.readAll(i32buf , 0, 4); int size = TFramedTransport.decodeFrameSize(i32buf); if (size < 0) { throw new TTransportException("Read a negative frame size (" + size + ")!"); } if (size > maxLength) { throw new TTransportException("Frame size (" + size + ") larger than max length (" + maxLength + ")!"); } readBuffer.fill(underlying, size); }
@Override public int getBytesRemainingInBuffer() { return readBuffer.getBytesRemainingInBuffer(); } }
/** * * @param underlying Transport that real reads and writes will go through to. * @param initialBufferCapacity The initial size of the read and write buffers. * In practice, it's not critical to set this unless you know in advance that * your messages are going to be very large. (You can pass * TFramedTransportWithReusableBuffer.DEFAULT_BUF_CAPACITY if you're only * using this constructor because you want to set the maxLength.) * @param maxLength The max frame size you are willing to read. You can use * this parameter to limit how much memory can be allocated. */ public TFastFramedTransport(TTransport underlying, int initialBufferCapacity, int maxLength) { this.underlying = underlying; this.maxLength = maxLength; writeBuffer = new AutoExpandingBufferWriteTransport(initialBufferCapacity, 1.5); readBuffer = new AutoExpandingBufferReadTransport(initialBufferCapacity, 1.5); }
@Override public byte[] getBuffer() { return readBuffer.getBuffer(); }
@Override public int getBufferPosition() { return readBuffer.getBufferPosition(); }
@Override public void consumeBuffer(int len) { readBuffer.consumeBuffer(len); }