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:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
TSocket
,TZlibTransport
public class TIOStreamTransport extends TEndpointTransport
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
Fields Modifier and Type Field Description protected java.io.InputStream
inputStream_
Underlying inputStreamprotected java.io.OutputStream
outputStream_
Underlying outputStream-
Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TIOStreamTransport()
Subclasses can invoke the default constructor and then assign the input streams in the open method.TIOStreamTransport(java.io.InputStream is)
Input stream constructor, constructs an input only transport.TIOStreamTransport(java.io.InputStream is, java.io.OutputStream os)
Two-way stream constructor.TIOStreamTransport(java.io.OutputStream os)
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, java.io.InputStream is)
Input stream constructor, constructs an input only transport.TIOStreamTransport(TConfiguration config, java.io.InputStream is, java.io.OutputStream os)
Two-way stream constructor.TIOStreamTransport(TConfiguration config, java.io.OutputStream os)
Output stream constructor, constructs an output only transport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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, getMaxMessageSize, resetConsumedMessageSize, updateKnownMessageSize
-
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, read, readAll, write, write
-
-
-
-
Constructor Detail
-
TIOStreamTransport
protected TIOStreamTransport(TConfiguration config) throws TTransportException
Subclasses can invoke the default constructor and then assign the input streams in the open method.- Throws:
TTransportException
-
TIOStreamTransport
protected TIOStreamTransport() throws TTransportException
Subclasses can invoke the default constructor and then assign the input streams in the open method.- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(TConfiguration config, java.io.InputStream is) throws TTransportException
Input stream constructor, constructs an input only transport.- Parameters:
config
-is
- Input stream to read from- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(java.io.InputStream is) throws TTransportException
Input stream constructor, constructs an input only transport.- Parameters:
is
- Input stream to read from- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(TConfiguration config, java.io.OutputStream os) throws TTransportException
Output stream constructor, constructs an output only transport.- Parameters:
config
-os
- Output stream to write to- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(java.io.OutputStream os) throws TTransportException
Output stream constructor, constructs an output only transport.- Parameters:
os
- Output stream to write to- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(TConfiguration config, java.io.InputStream is, java.io.OutputStream os) throws TTransportException
Two-way stream constructor.- Parameters:
config
-is
- Input stream to read fromos
- Output stream to read from- Throws:
TTransportException
-
TIOStreamTransport
public TIOStreamTransport(java.io.InputStream is, java.io.OutputStream os) throws TTransportException
Two-way stream constructor.- Parameters:
is
- Input stream to read fromos
- Output stream to read from- Throws:
TTransportException
-
-
Method Detail
-
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
public void open() throws TTransportException
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classTTransport
-
read
public int read(byte[] buf, int off, int len) throws TTransportException
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
public void write(byte[] buf, int off, int len) throws TTransportException
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
public void flush() throws TTransportException
Flushes the underlying output stream if not null.- Overrides:
flush
in classTTransport
- Throws:
TTransportException
- if there was an error writing out data.
-
-