Package org.apache.thrift.transport
Class TTransport
java.lang.Object
org.apache.thrift.transport.TTransport
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
TEndpointTransport
,TFileTransport
,TLayeredTransport
Generic class that encapsulates the I/O layer. This is basically a thin wrapper around the
combined functionality of Java input/output streams.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
checkReadBytesAvailable
(long numBytes) abstract void
close()
Closes the transport.void
consumeBuffer
(int len) Consume len bytes from the underlying buffer.void
flush()
Flush any pending data out of a transport buffer.byte[]
Access the protocol's underlying buffer directly.int
Return the index within the underlying buffer that specifies the next spot that should be read from.int
Get the number of bytes remaining in the underlying buffer.abstract TConfiguration
abstract boolean
isOpen()
Queries whether the transport is open.abstract void
open()
Opens the transport for reading/writing.boolean
peek()
Is there more data to be read?abstract int
read
(byte[] buf, int off, int len) Reads up to len bytes into buffer buf, starting at offset off.int
read
(ByteBuffer dst) Reads a sequence of bytes from this channel into the given buffer.int
readAll
(byte[] buf, int off, int len) Guarantees that all of len bytes are actually read off the transport.abstract void
updateKnownMessageSize
(long size) void
write
(byte[] buf) Writes the buffer to the outputabstract void
write
(byte[] buf, int off, int len) Writes up to len bytes from the buffer.int
write
(ByteBuffer src) Writes a sequence of bytes to the buffer.
-
Constructor Details
-
TTransport
public TTransport()
-
-
Method Details
-
isOpen
public abstract boolean isOpen()Queries whether the transport is open.- Returns:
- True if the transport is open.
-
peek
public boolean peek()Is there more data to be read?- Returns:
- True if the remote side is still alive and feeding us
-
open
Opens the transport for reading/writing.- Throws:
TTransportException
- if the transport could not be opened
-
close
public abstract void close()Closes the transport.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
read
Reads a sequence of bytes from this channel into the given buffer. An attempt is made to read up to the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked. Upon return the buffer's position will move forward the number of bytes read; its limit will not have changed. Subclasses are encouraged to provide a more efficient implementation of this method.- Parameters:
dst
- The buffer into which bytes are to be transferred- Returns:
- The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
- Throws:
TTransportException
- if there was an error reading data
-
read
Reads up to len bytes into buffer buf, starting at offset off.- Parameters:
buf
- Array to read intooff
- Index to start reading atlen
- Maximum number of bytes to read- Returns:
- The number of bytes actually read
- Throws:
TTransportException
- if there was an error reading data
-
readAll
Guarantees that all of len bytes are actually read off the transport.- Parameters:
buf
- Array to read intooff
- Index to start reading atlen
- Maximum number of bytes to read- Returns:
- The number of bytes actually read, which must be equal to len
- Throws:
TTransportException
- if there was an error reading data
-
write
Writes the buffer to the output- Parameters:
buf
- The output data buffer- Throws:
TTransportException
- if an error occurs writing data
-
write
Writes up to len bytes from the buffer.- Parameters:
buf
- The output data bufferoff
- The offset to start writing fromlen
- The number of bytes to write- Throws:
TTransportException
- if there was an error writing data
-
write
Writes a sequence of bytes to the buffer. An attempt is made to write all remaining bytes in the buffer, that is, src.remaining(), at the moment this method is invoked. Upon return the buffer's position will updated; its limit will not have changed. Subclasses are encouraged to provide a more efficient implementation of this method.- Parameters:
src
- The buffer from which bytes are to be retrieved- Returns:
- The number of bytes written, possibly zero
- Throws:
TTransportException
- if there was an error writing data
-
flush
Flush any pending data out of a transport buffer.- Throws:
TTransportException
- if there was an error writing out data.
-
getBuffer
public byte[] getBuffer()Access the protocol's underlying buffer directly. If this is not a buffered transport, return null.- Returns:
- protocol's Underlying buffer
-
getBufferPosition
public int getBufferPosition()Return the index within the underlying buffer that specifies the next spot that should be read from.- Returns:
- index within the underlying buffer that specifies the next spot that should be read from
-
getBytesRemainingInBuffer
public int getBytesRemainingInBuffer()Get the number of bytes remaining in the underlying buffer. Returns -1 if this is a non-buffered transport.- Returns:
- the number of bytes remaining in the underlying buffer.
Returns -1 if this is a non-buffered transport.
-
consumeBuffer
public void consumeBuffer(int len) Consume len bytes from the underlying buffer.- Parameters:
len
- the number of bytes to consume from the underlying buffer.
-
getConfiguration
-
updateKnownMessageSize
- Throws:
TTransportException
-
checkReadBytesAvailable
- Throws:
TTransportException
-