public class DirectFileReadDataSource extends Object implements DataSource
DataSource implementation that relies on direct reads from a RandomAccessFile.
It should be slower than FileDataSourceImpl but does not incur the implicit file locks of
memory mapped I/O on some JVMs. This implementation allows for a more controlled deletion of files
and might be preferred when working with temporary files.| Constructor and Description |
|---|
DirectFileReadDataSource(File f) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Tries to free all resources.
|
ByteBuffer |
map(long startPosition,
long size)
Maps a part of this
DataSource into a ByteBuffer. |
long |
position()
Returns the DataSource's current position.
|
void |
position(long nuPos)
Sets the DataSource's position.
|
int |
read(ByteBuffer byteBuffer)
Reads a sequence of bytes from this channel into the given buffer.
|
int |
readAllInOnce(ByteBuffer byteBuffer) |
long |
size()
Returns the current size of this DataSource.
|
String |
toString() |
long |
transferTo(long position,
long count,
WritableByteChannel target)
Transfers bytes from this DataSource to the given writable byte
channel.
|
public DirectFileReadDataSource(File f) throws IOException
IOExceptionpublic int read(ByteBuffer byteBuffer) throws IOException
DataSourceread in interface DataSourcebyteBuffer - sink for this read operationIOException - If some I/O error occurspublic int readAllInOnce(ByteBuffer byteBuffer) throws IOException
IOExceptionpublic long size()
throws IOException
DataSourcesize in interface DataSourceIOException - If some I/O error occurspublic long position()
throws IOException
DataSourceposition in interface DataSourceIOException - If some I/O error occurspublic void position(long nuPos)
throws IOException
DataSourceposition in interface DataSourcenuPos - The new position, a non-negative integer counting
the number of bytes from the beginning of the dataIOException - If some I/O error occurspublic long transferTo(long position,
long count,
WritableByteChannel target)
throws IOException
DataSourcetransferTo in interface DataSourceposition - The position within the DataSource at which the transfer is to begin;
must be non-negativecount - The maximum number of bytes to be transferred; must be
non-negativetarget - The target channelIOException - If some I/O error occurspublic ByteBuffer map(long startPosition, long size) throws IOException
DataSourceDataSource into a ByteBuffer. It might utilize
an operating system supported memory mapped file or potentially just reads the requested
portion of the file into the memory.map in interface DataSourcestartPosition - where the requested block startsize - size of the requested blockDataSourceIOException - If some I/O error occurspublic void close()
throws IOException
DataSourceclose in interface DataSourceclose in interface Closeableclose in interface AutoCloseableIOException - If some I/O error occursCopyright © 2016. All rights reserved.