public abstract class BlockSource extends Object implements AutoCloseable
BlockSource implementations must decide if they will be thread-safe,
or not.
| Constructor and Description |
|---|
BlockSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
adviseSequentialRead(long startPos,
long endPos)
Advise the
BlockSource a sequential scan is starting. |
abstract void |
close() |
static BlockSource |
from(byte[] content)
Wrap a byte array as a
BlockSource. |
static BlockSource |
from(FileChannel ch)
Read from a
FileChannel. |
static BlockSource |
from(FileInputStream in)
Read from a
FileInputStream. |
abstract ByteBuffer |
read(long position,
int blockSize)
Read a block from the file.
|
abstract long |
size()
Determine the size of the file.
|
public static BlockSource from(byte[] content)
BlockSource.content - input file.content.public static BlockSource from(FileInputStream in)
FileInputStream.
The returned BlockSource is not thread-safe, as it must seek the
file channel to read a block.
in - the file. The BlockSource will close in.in.public static BlockSource from(FileChannel ch)
FileChannel.
The returned BlockSource is not thread-safe, as it must seek the
file channel to read a block.
ch - the file. The BlockSource will close ch.ch.public abstract ByteBuffer read(long position, int blockSize) throws IOException
To reduce copying, the returned ByteBuffer should have an accessible
array and arrayOffset() == 0. The caller will discard the
ByteBuffer and directly use the backing array.
position - position of the block in the file, specified in bytes from the
beginning of the file.blockSize - size to read.IOException - if block cannot be read.public abstract long size()
throws IOException
IOException - if size cannot be obtained.public void adviseSequentialRead(long startPos,
long endPos)
BlockSource a sequential scan is starting.startPos - starting position.endPos - ending position.public abstract void close()
close in interface AutoCloseableCopyright © 2018 Eclipse JGit Project. All rights reserved.