Package org.globus.ftp
Class FileRandomIO
- java.lang.Object
-
- org.globus.ftp.FileRandomIO
-
- All Implemented Interfaces:
DataSink
,DataSource
public class FileRandomIO extends java.lang.Object implements DataSink, DataSource
Thread safe reference implementation of DataSink and DataSource. Implements reading and writing data to a local file. Note: Does not work withSession.STREAM
transfer mode, only withGridFTPSession.EBLOCK
mode.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bufferSize
static int
DEFAULT_BUFFER_SIZE
protected java.io.RandomAccessFile
file
protected long
offset
-
Constructor Summary
Constructors Constructor Description FileRandomIO(java.io.RandomAccessFile file)
Behave like FileRandomIO(file, DEFAULT_BUFFER_SIZE)FileRandomIO(java.io.RandomAccessFile file, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the underlying fileBuffer
read()
In this implementation, each read() returns data sequentially.long
totalSize()
Optional operation.void
write(Buffer buffer)
Writes the specified buffer to this data sink.
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
bufferSize
protected int bufferSize
-
file
protected java.io.RandomAccessFile file
-
offset
protected long offset
-
-
Constructor Detail
-
FileRandomIO
public FileRandomIO(java.io.RandomAccessFile file)
Behave like FileRandomIO(file, DEFAULT_BUFFER_SIZE)- Parameters:
file
- local file that will be be used as data source or destination
-
FileRandomIO
public FileRandomIO(java.io.RandomAccessFile file, int bufferSize)
- Parameters:
file
- local file that will be be used as data source or destinationbufferSize
- size of the buffer returned during single read operation
-
-
Method Detail
-
write
public void write(Buffer buffer) throws java.io.IOException
Description copied from interface:DataSink
Writes the specified buffer to this data sink.
Note:buffer.getOffset()
might return -1 if the transfer mode used does not support data offsets, for example stream transfer mode.
-
read
public Buffer read() throws java.io.IOException
In this implementation, each read() returns data sequentially.- Specified by:
read
in interfaceDataSource
- Returns:
- The data buffer read. Null, if there is no more data to be read.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
close
public void close() throws java.io.IOException
Closes the underlying file- Specified by:
close
in interfaceDataSink
- Specified by:
close
in interfaceDataSource
- Throws:
java.io.IOException
- if an I/O error occurs.
-
totalSize
public long totalSize() throws java.io.IOException
Description copied from interface:DataSource
Optional operation. Returns the total size, in bytes, of the data in this source. If the implementation is not able to provide a total size for the data source, it should return -1- Specified by:
totalSize
in interfaceDataSource
- Throws:
java.io.IOException
- if an I/O exception occurs
-
-