Package org.apache.thrift.transport
Class TFileTransport
- java.lang.Object
-
- org.apache.thrift.transport.TTransport
-
- org.apache.thrift.transport.TFileTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class TFileTransport extends TTransport
FileTransport implementation of the TTransport interface. Currently this is a straightforward port of the cpp implementation It may make better sense to provide a basic stream access on top of the framed file format The FileTransport can then be a user of this framed file format with some additional logic for chunking.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTFileTransport.ChunkStatestatic classTFileTransport.Eventstatic classTFileTransport.TailPolicystatic classTFileTransport.TruncableBufferedInputStream
-
Field Summary
Fields Modifier and Type Field Description protected TSeekableFileinputFile_Underlying file being readprotected java.io.OutputStreamoutputStream_Underlying outputStream
-
Constructor Summary
Constructors Constructor Description TFileTransport(java.lang.String path, boolean readOnly)File Transport ctorTFileTransport(TSeekableFile inputFile, boolean readOnly)File Transport ctor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the transport.voidflush()Flush any pending data out of a transport buffer.intgetCurChunk()intgetNumChunks()TFileTransport.TailPolicygetTailPolicy()Get File Tailing PolicybooleanisOpen()open if both input/output open unless readonlystatic voidmain(java.lang.String[] args)test programvoidopen()Diverging from the cpp model and sticking to the TSocket model Files are not opened in ctor - but in explicit open callintread(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)Cloned from TTransport.java:readAll().voidseekToChunk(int chunk)voidseekToEnd()TFileTransport.TailPolicysetTailPolicy(TFileTransport.TailPolicy policy)Set file Tailing Policyvoidwrite(byte[] buf, int off, int len)Writes up to len bytes from the buffer.-
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, write
-
-
-
-
Field Detail
-
inputFile_
protected TSeekableFile inputFile_
Underlying file being read
-
outputStream_
protected java.io.OutputStream outputStream_
Underlying outputStream
-
-
Constructor Detail
-
TFileTransport
public TFileTransport(java.lang.String path, boolean readOnly) throws java.io.IOExceptionFile Transport ctor- Parameters:
path- File path to read and write fromreadOnly- Whether this is a read-only transport- Throws:
java.io.IOException
-
TFileTransport
public TFileTransport(TSeekableFile inputFile, boolean readOnly)
File Transport ctor- Parameters:
inputFile- open TSeekableFile to read/write fromreadOnly- Whether this is a read-only transport
-
-
Method Detail
-
getTailPolicy
public TFileTransport.TailPolicy getTailPolicy()
Get File Tailing Policy- Returns:
- current read policy
-
setTailPolicy
public TFileTransport.TailPolicy setTailPolicy(TFileTransport.TailPolicy policy)
Set file Tailing Policy- Parameters:
policy- New policy to set- Returns:
- Old policy
-
isOpen
public boolean isOpen()
open if both input/output open unless readonly- Specified by:
isOpenin classTTransport- Returns:
- true
-
open
public void open() throws TTransportExceptionDiverging from the cpp model and sticking to the TSocket model Files are not opened in ctor - but in explicit open call- Specified by:
openin classTTransport- Throws:
TTransportException- if the transport could not be opened
-
close
public void close()
Closes the transport.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classTTransport
-
readAll
public int readAll(byte[] buf, int off, int len) throws TTransportExceptionCloned from TTransport.java:readAll(). Only difference is throwing an EOF exception where one is detected.- Overrides:
readAllin 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, which must be equal to len
- Throws:
TTransportException- if there was an error reading data
-
read
public int read(byte[] buf, int off, int len) throws TTransportExceptionReads up to len bytes into buffer buf, starting at offset off.- 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
-
getNumChunks
public int getNumChunks() throws TTransportException- Throws:
TTransportException
-
getCurChunk
public int getCurChunk() throws TTransportException- Throws:
TTransportException
-
seekToChunk
public void seekToChunk(int chunk) throws TTransportException- Throws:
TTransportException
-
seekToEnd
public void seekToEnd() throws TTransportException- Throws:
TTransportException
-
write
public void write(byte[] buf, int off, int len) throws TTransportExceptionWrites up to len bytes from the buffer.- 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 TTransportExceptionFlush any pending data out of a transport buffer.- Overrides:
flushin classTTransport- Throws:
TTransportException- if there was an error writing out data.
-
main
public static void main(java.lang.String[] args) throws java.lang.Exceptiontest program- Throws:
java.lang.Exception
-
-