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.InputStreaminputStream_Underlying inputStreamprotected java.io.OutputStreamoutputStream_Underlying outputStream-
Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTIOStreamTransport()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.protectedTIOStreamTransport(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 voidclose()Closes both the input and output streams.voidflush()Flushes the underlying output stream if not null.booleanisOpen()Queries whether the transport is open.voidopen()The streams must already be open.intread(byte[] buf, int off, int len)Reads from the underlying input stream if not null.voidwrite(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 TTransportExceptionSubclasses 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 TTransportExceptionInput 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 TTransportExceptionOutput 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 TTransportExceptionTwo-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:TTransportQueries whether the transport is open.- Specified by:
isOpenin classTTransport- Returns:
- false after close is called.
-
open
public void open() throws TTransportExceptionThe streams must already be open. This method does nothing.- Specified by:
openin classTTransport- Throws:
TTransportException- if the transport could not be opened
-
close
public void close()
Closes both the input and output streams.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classTTransport
-
read
public int read(byte[] buf, int off, int len) throws TTransportExceptionReads from the underlying input stream if not null.- Specified by:
readin 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 TTransportExceptionWrites to the underlying output stream if not null.- Specified by:
writein 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 TTransportExceptionFlushes the underlying output stream if not null.- Overrides:
flushin classTTransport- Throws:
TTransportException- if there was an error writing out data.
-
-