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
IOException
public int read(ByteBuffer byteBuffer) throws IOException
DataSource
read
in interface DataSource
byteBuffer
- sink for this read operationIOException
- If some I/O error occurspublic int readAllInOnce(ByteBuffer byteBuffer) throws IOException
IOException
public long size() throws IOException
DataSource
size
in interface DataSource
IOException
- If some I/O error occurspublic long position() throws IOException
DataSource
position
in interface DataSource
IOException
- If some I/O error occurspublic void position(long nuPos) throws IOException
DataSource
position
in interface DataSource
nuPos
- 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
DataSource
transferTo
in interface DataSource
position
- 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
DataSource
DataSource
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 DataSource
startPosition
- where the requested block startsize
- size of the requested blockDataSource
IOException
- If some I/O error occurspublic void close() throws IOException
DataSource
close
in interface DataSource
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If some I/O error occursCopyright © 2014. All rights reserved.