public class MemoryDataSourceImpl extends Object implements DataSource
Constructor and Description |
---|
MemoryDataSourceImpl(byte[] data) |
MemoryDataSourceImpl(ByteBuffer buffer) |
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.
|
long |
size()
Returns the current size of this DataSource.
|
long |
transferTo(long position,
long count,
WritableByteChannel target)
Transfers bytes from this DataSource to the given writable byte
channel.
|
public MemoryDataSourceImpl(byte[] data)
public MemoryDataSourceImpl(ByteBuffer buffer)
public int read(ByteBuffer byteBuffer) throws IOException
DataSource
read
in interface DataSource
byteBuffer
- sink for this read operationIOException
- If some I/O error occurspublic 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 © 2015. All rights reserved.