public class MemoryDataSourceImpl extends Object implements DataSource
Constructor and Description |
---|
MemoryDataSourceImpl(byte[] data) |
MemoryDataSourceImpl(ByteBuffer buffer) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
ByteBuffer |
map(long startPosition,
long size) |
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
Bytes are read starting at this channel's current position, and then the file position is updated with the number of bytes actually read.
read
in interface DataSource
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
public 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
An attempt should be made to read up to count bytes starting at the given position in this DataSource and write them to the target channel. An invocation of this method may or may not transfer all of the requested bytes;
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
public ByteBuffer map(long startPosition, long size) throws IOException
map
in interface DataSource
IOException
public void close() throws IOException
close
in interface DataSource
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2014. All rights reserved.