Package org.apache.thrift.transport
Class TFileTransport
java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TFileTransport
- All Implemented Interfaces:
Closeable,AutoCloseable
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 ClassesModifier and TypeClassDescriptionstatic classstatic classstatic enumstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TSeekableFileUnderlying file being readprotected OutputStreamUnderlying outputStream -
Constructor Summary
ConstructorsConstructorDescriptionTFileTransport(String path, boolean readOnly) File Transport ctorTFileTransport(TSeekableFile inputFile, boolean readOnly) File Transport ctor -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckReadBytesAvailable(long numBytes) voidclose()Closes the transport.voidflush()Flush any pending data out of a transport buffer.intintGet File Tailing PolicybooleanisOpen()open if both input/output open unless readonlystatic voidtest 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) voidSet file Tailing PolicyvoidupdateKnownMessageSize(long size) voidwrite(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, read, write, write
-
Field Details
-
inputFile_
Underlying file being read -
outputStream_
Underlying outputStream
-
-
Constructor Details
-
TFileTransport
File Transport ctor- Parameters:
path- File path to read and write fromreadOnly- Whether this is a read-only transport- Throws:
IOException- if there is an error accessing the file.
-
TFileTransport
File Transport ctor- Parameters:
inputFile- open TSeekableFile to read/write fromreadOnly- Whether this is a read-only transport
-
-
Method Details
-
getTailPolicy
Get File Tailing Policy- Returns:
- current read policy
-
setTailPolicy
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
Diverging 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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classTTransport
-
readAll
Cloned 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
Reads 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
- Throws:
TTransportException
-
getCurChunk
- Throws:
TTransportException
-
seekToChunk
- Throws:
TTransportException
-
seekToEnd
- Throws:
TTransportException
-
write
Writes 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
Flush any pending data out of a transport buffer.- Overrides:
flushin classTTransport- Throws:
TTransportException- if there was an error writing out data.
-
getConfiguration
- Specified by:
getConfigurationin classTTransport
-
updateKnownMessageSize
- Specified by:
updateKnownMessageSizein classTTransport- Throws:
TTransportException
-
checkReadBytesAvailable
- Specified by:
checkReadBytesAvailablein classTTransport- Throws:
TTransportException
-
main
test program- Throws:
Exception
-