Package org.apache.thrift.transport
Class TSimpleFileTransport
java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TEndpointTransport
org.apache.thrift.transport.TSimpleFileTransport
- All Implemented Interfaces:
Closeable
,AutoCloseable
Basic file support for the TTransport interface
-
Field Summary
Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
Constructor Summary
ConstructorDescriptionTSimpleFileTransport
(String path) Create a transport backed by a simple read only disk file (implicitly opens file)TSimpleFileTransport
(String path, boolean read, boolean write) Create a transport backed by a simple file Implicitly opens file to conform to C++ behavior.TSimpleFileTransport
(String path, boolean read, boolean write, boolean openFile) Create a transport backed by a simple fileTSimpleFileTransport
(TConfiguration config, String path, boolean read, boolean write, boolean openFile) Create a transport backed by a simple file -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close file, subsequent read/write activity will throw exceptionslong
Return current file pointer position in bytes from beginning of fileboolean
isOpen()
Test file statuslong
length()
Return the length of the file in bytesvoid
open()
Open file if not previously opened.int
read
(byte[] buf, int off, int len) Read up to len many bytes into buf at offsetvoid
seek
(long offset) Move file pointer to specified offset, new read/write calls will act herevoid
write
(byte[] buf, int off, int len) Write len many bytes from buff starting at offsetMethods inherited from class org.apache.thrift.transport.TEndpointTransport
checkReadBytesAvailable, countConsumedMessageBytes, getConfiguration, getMaxFrameSize, getMaxMessageSize, resetConsumedMessageSize, setMaxFrameSize, updateKnownMessageSize
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, flush, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, read, readAll, write, write
-
Constructor Details
-
TSimpleFileTransport
public TSimpleFileTransport(String path, boolean read, boolean write, boolean openFile) throws TTransportException Create a transport backed by a simple file- Parameters:
path
- the path to the file to open/createread
- true to support read operationswrite
- true to support write operationsopenFile
- true to open the file on construction- Throws:
TTransportException
- if file open fails
-
TSimpleFileTransport
public TSimpleFileTransport(TConfiguration config, String path, boolean read, boolean write, boolean openFile) throws TTransportException Create a transport backed by a simple file- Parameters:
config
-path
- the path to the file to open/createread
- true to support read operationswrite
- true to support write operationsopenFile
- true to open the file on construction- Throws:
TTransportException
- if file open fails
-
TSimpleFileTransport
Create a transport backed by a simple file Implicitly opens file to conform to C++ behavior.- Parameters:
path
- the path to the file to open/createread
- true to support read operationswrite
- true to support write operations- Throws:
TTransportException
- if file open fails
-
TSimpleFileTransport
Create a transport backed by a simple read only disk file (implicitly opens file)- Parameters:
path
- the path to the file to open/create- Throws:
TTransportException
- if file open fails
-
-
Method Details
-
isOpen
public boolean isOpen()Test file status- Specified by:
isOpen
in classTTransport
- Returns:
- true if open, otherwise false
-
open
Open file if not previously opened.- Specified by:
open
in classTTransport
- Throws:
TTransportException
- if open fails
-
close
public void close()Close file, subsequent read/write activity will throw exceptions- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classTTransport
-
read
Read up to len many bytes into buf at offset- Specified by:
read
in classTTransport
- Parameters:
buf
- houses bytes readoff
- offset into buff to begin writing tolen
- maximum number of bytes to read- Returns:
- number of bytes actually read
- Throws:
TTransportException
- on read failure
-
write
Write len many bytes from buff starting at offset- Specified by:
write
in classTTransport
- Parameters:
buf
- buffer containing bytes to writeoff
- offset into buffer to begin writing fromlen
- number of bytes to write- Throws:
TTransportException
- on write failure
-
seek
Move file pointer to specified offset, new read/write calls will act here- Parameters:
offset
- bytes from beginning of file to move pointer to- Throws:
TTransportException
- is seek fails
-
length
Return the length of the file in bytes- Returns:
- length of the file in bytes
- Throws:
TTransportException
- if file access fails
-
getFilePointer
Return current file pointer position in bytes from beginning of file- Returns:
- file pointer position
- Throws:
TTransportException
- if file access fails
-