Package org.apache.thrift.transport
Class TIOStreamTransport
- java.lang.Object
-
- org.apache.thrift.transport.TTransport
-
- org.apache.thrift.transport.TIOStreamTransport
-
- Direct Known Subclasses:
TSocket
public class TIOStreamTransport extends TTransport
This is the most commonly used base transport. It takes an InputStream and an OutputStream and uses those to perform all 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
-
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.TIOStreamTransport(java.io.InputStream is, java.io.OutputStream os)
Two-way stream constructor.TIOStreamTransport(java.io.OutputStream os)
Output stream constructor.
-
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()
The streams must already be open at construction time, so this should always return true.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.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, write
-
-
-
-
Constructor Detail
-
TIOStreamTransport
protected TIOStreamTransport()
Subclasses can invoke the default constructor and then assign the input streams in the open method.
-
TIOStreamTransport
public TIOStreamTransport(java.io.InputStream is)
Input stream constructor.- Parameters:
is
- Input stream to read from
-
TIOStreamTransport
public TIOStreamTransport(java.io.OutputStream os)
Output stream constructor.- Parameters:
os
- Output stream to read from
-
TIOStreamTransport
public TIOStreamTransport(java.io.InputStream is, java.io.OutputStream os)
Two-way stream constructor.- Parameters:
is
- Input stream to read fromos
- Output stream to read from
-
-
Method Detail
-
isOpen
public boolean isOpen()
The streams must already be open at construction time, so this should always return true.- Specified by:
isOpen
in classTTransport
- Returns:
- true
-
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 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.
-
-