Package org.apache.thrift.transport
Class TIOStreamTransport
java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TEndpointTransport
org.apache.thrift.transport.TIOStreamTransport
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
TSocket
,TZlibTransport
This is the most commonly used base transport. It takes an InputStream or an OutputStream or both
and uses it/them to perform transport operations. This allows for compatibility with all the nice
constructs Java already has to provide a variety of types of streams.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InputStream
Underlying inputStreamprotected OutputStream
Underlying outputStreamFields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Subclasses can invoke the default constructor and then assign the input streams in the open method.Input stream constructor, constructs an input only transport.Two-way stream constructor.Output stream constructor, constructs an output only transport.protected
TIOStreamTransport
(TConfiguration config) Subclasses can invoke the default constructor and then assign the input streams in the open method.TIOStreamTransport
(TConfiguration config, InputStream is) Input stream constructor, constructs an input only transport.TIOStreamTransport
(TConfiguration config, InputStream is, OutputStream os) Two-way stream constructor.TIOStreamTransport
(TConfiguration config, OutputStream os) Output stream constructor, constructs an output only transport. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes both the input and output streams.void
flush()
Flushes the underlying output stream if not null.boolean
isOpen()
Queries whether the transport is open.void
open()
The streams must already be open.int
read
(byte[] buf, int off, int len) Reads from the underlying input stream if not null.void
write
(byte[] buf, int off, int len) Writes to the underlying output stream if not null.Methods inherited from class org.apache.thrift.transport.TEndpointTransport
checkReadBytesAvailable, countConsumedMessageBytes, getConfiguration, getMaxFrameSize, getMaxMessageSize, resetConsumedMessageSize, setMaxFrameSize, updateKnownMessageSize
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, read, readAll, write, write
-
Field Details
-
inputStream_
Underlying inputStream -
outputStream_
Underlying outputStream
-
-
Constructor Details
-
TIOStreamTransport
Subclasses can invoke the default constructor and then assign the input streams in the open method.- Throws:
TTransportException
-
TIOStreamTransport
Subclasses can invoke the default constructor and then assign the input streams in the open method.- Throws:
TTransportException
-
TIOStreamTransport
Input stream constructor, constructs an input only transport.- Parameters:
config
-is
- Input stream to read from- Throws:
TTransportException
-
TIOStreamTransport
Input stream constructor, constructs an input only transport.- Parameters:
is
- Input stream to read from- Throws:
TTransportException
-
TIOStreamTransport
Output stream constructor, constructs an output only transport.- Parameters:
config
-os
- Output stream to write to- Throws:
TTransportException
-
TIOStreamTransport
Output stream constructor, constructs an output only transport.- Parameters:
os
- Output stream to write to- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(TConfiguration config, InputStream is, OutputStream os) throws TTransportException Two-way stream constructor.- Parameters:
config
-is
- Input stream to read fromos
- Output stream to read from- Throws:
TTransportException
-
TIOStreamTransport
Two-way stream constructor.- Parameters:
is
- Input stream to read fromos
- Output stream to read from- Throws:
TTransportException
-
-
Method Details
-
isOpen
public boolean isOpen()Description copied from class:TTransport
Queries whether the transport is open.- Specified by:
isOpen
in classTTransport
- Returns:
- false after close is called.
-
open
The streams must already be open. This method does nothing.- Specified by:
open
in classTTransport
- Throws:
TTransportException
- if the transport could not be opened
-
close
public void close()Closes both the input and output streams.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classTTransport
-
read
Reads from the underlying input stream if not null.- Specified by:
read
in classTTransport
- 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
-
write
Writes to the underlying output stream if not null.- Specified by:
write
in classTTransport
- 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
Flushes the underlying output stream if not null.- Overrides:
flush
in classTTransport
- Throws:
TTransportException
- if there was an error writing out data.
-