Package org.apache.thrift.transport
Class TSimpleFileTransport
- java.lang.Object
-
- org.apache.thrift.transport.TTransport
-
- org.apache.thrift.transport.TSimpleFileTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class TSimpleFileTransport extends TTransport
Basic file support for the TTransport interface
-
-
Constructor Summary
Constructors Constructor Description TSimpleFileTransport(java.lang.String path)Create a transport backed by a simple read only disk file (implicitly opens file)TSimpleFileTransport(java.lang.String path, boolean read, boolean write)Create a transport backed by a simple file Implicitly opens file to conform to C++ behavior.TSimpleFileTransport(java.lang.String path, boolean read, boolean write, boolean openFile)Create a transport backed by a simple file
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close file, subsequent read/write activity will throw exceptionslonggetFilePointer()Return current file pointer position in bytes from beginning of filebooleanisOpen()Test file statuslonglength()Return the length of the file in bytesvoidopen()Open file if not previously opened.intread(byte[] buf, int off, int len)Read up to len many bytes into buf at offsetvoidseek(long offset)Move file pointer to specified offset, new read/write calls will act herevoidwrite(byte[] buf, int off, int len)Write len many bytes from buff starting at offset-
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, flush, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, write
-
-
-
-
Constructor Detail
-
TSimpleFileTransport
public TSimpleFileTransport(java.lang.String path, boolean read, boolean write, boolean openFile) throws TTransportExceptionCreate 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(java.lang.String path, boolean read, boolean write) throws TTransportExceptionCreate 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
public TSimpleFileTransport(java.lang.String path) throws TTransportExceptionCreate 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 Detail
-
isOpen
public boolean isOpen()
Test file status- Specified by:
isOpenin classTTransport- Returns:
- true if open, otherwise false
-
open
public void open() throws TTransportExceptionOpen file if not previously opened.- Specified by:
openin classTTransport- Throws:
TTransportException- if open fails
-
close
public void close()
Close file, subsequent read/write activity will throw exceptions- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classTTransport
-
read
public int read(byte[] buf, int off, int len) throws TTransportExceptionRead up to len many bytes into buf at offset- Specified by:
readin 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
public void write(byte[] buf, int off, int len) throws TTransportExceptionWrite len many bytes from buff starting at offset- Specified by:
writein 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
public void seek(long offset) throws TTransportExceptionMove 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
public long length() throws TTransportExceptionReturn the length of the file in bytes- Returns:
- length of the file in bytes
- Throws:
TTransportException- if file access fails
-
getFilePointer
public long getFilePointer() throws TTransportExceptionReturn current file pointer position in bytes from beginning of file- Returns:
- file pointer position
- Throws:
TTransportException- if file access fails
-
-