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
Modifier and TypeClassDescriptionstatic class
static class
static enum
static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected TSeekableFile
Underlying file being readprotected OutputStream
Underlying outputStream -
Constructor Summary
ConstructorDescriptionTFileTransport
(String path, boolean readOnly) File Transport ctorTFileTransport
(TSeekableFile inputFile, boolean readOnly) File Transport ctor -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkReadBytesAvailable
(long numBytes) void
close()
Closes the transport.void
flush()
Flush any pending data out of a transport buffer.int
int
Get File Tailing Policyboolean
isOpen()
open if both input/output open unless readonlystatic void
test programvoid
open()
Diverging from the cpp model and sticking to the TSocket model Files are not opened in ctor - but in explicit open callint
read
(byte[] buf, int off, int len) Reads up to len bytes into buffer buf, starting at offset off.int
readAll
(byte[] buf, int off, int len) Cloned from TTransport.java:readAll().void
seekToChunk
(int chunk) void
Set file Tailing Policyvoid
updateKnownMessageSize
(long size) void
write
(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:
isOpen
in 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:
open
in classTTransport
- Throws:
TTransportException
- if the transport could not be opened
-
close
public void close()Closes the transport.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classTTransport
-
readAll
Cloned from TTransport.java:readAll(). Only difference is throwing an EOF exception where one is detected.- Overrides:
readAll
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, 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:
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
-
getNumChunks
- Throws:
TTransportException
-
getCurChunk
- Throws:
TTransportException
-
seekToChunk
- Throws:
TTransportException
-
seekToEnd
- Throws:
TTransportException
-
write
Writes up to len bytes from the buffer.- 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
Flush any pending data out of a transport buffer.- Overrides:
flush
in classTTransport
- Throws:
TTransportException
- if there was an error writing out data.
-
getConfiguration
- Specified by:
getConfiguration
in classTTransport
-
updateKnownMessageSize
- Specified by:
updateKnownMessageSize
in classTTransport
- Throws:
TTransportException
-
checkReadBytesAvailable
- Specified by:
checkReadBytesAvailable
in classTTransport
- Throws:
TTransportException
-
main
test program- Throws:
Exception
-