Package org.apache.thrift.transport
Class TTransport
- java.lang.Object
-
- org.apache.thrift.transport.TTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
AutoExpandingBufferReadTransport,AutoExpandingBufferWriteTransport,TByteBuffer,TFastFramedTransport,TFileTransport,TFramedTransport,THttpClient,TIOStreamTransport,TMemoryBuffer,TMemoryInputTransport,TNonblockingTransport,TSaslClientTransport,TSaslServerTransport,TSimpleFileTransport
public abstract class TTransport extends java.lang.Object implements java.io.CloseableGeneric class that encapsulates the I/O layer. This is basically a thin wrapper around the combined functionality of Java input/output streams.
-
-
Constructor Summary
Constructors Constructor Description TTransport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclose()Closes the transport.voidconsumeBuffer(int len)Consume len bytes from the underlying buffer.voidflush()Flush any pending data out of a transport buffer.byte[]getBuffer()Access the protocol's underlying buffer directly.intgetBufferPosition()Return the index within the underlying buffer that specifies the next spot that should be read from.intgetBytesRemainingInBuffer()Get the number of bytes remaining in the underlying buffer.abstract booleanisOpen()Queries whether the transport is open.abstract voidopen()Opens the transport for reading/writing.booleanpeek()Is there more data to be read?abstract intread(byte[] buf, int off, int len)Reads up to len bytes into buffer buf, starting at offset off.intreadAll(byte[] buf, int off, int len)Guarantees that all of len bytes are actually read off the transport.voidwrite(byte[] buf)Writes the buffer to the outputabstract voidwrite(byte[] buf, int off, int len)Writes up to len bytes from the buffer.
-
-
-
Method Detail
-
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
public abstract void open() throws TTransportExceptionOpens the transport for reading/writing.- Throws:
TTransportException- if the transport could not be opened
-
close
public abstract void close()
Closes the transport.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
read
public abstract int read(byte[] buf, int off, int len) throws TTransportExceptionReads 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
public int readAll(byte[] buf, int off, int len) throws TTransportExceptionGuarantees 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
public void write(byte[] buf) throws TTransportExceptionWrites the buffer to the output- Parameters:
buf- The output data buffer- Throws:
TTransportException- if an error occurs writing data
-
write
public abstract void write(byte[] buf, int off, int len) throws TTransportExceptionWrites 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
-
flush
public void flush() throws TTransportExceptionFlush 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-
-
-