Class BlockSource
java.lang.Object
org.eclipse.jgit.internal.storage.io.BlockSource
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DfsReftable.CacheSource
Provides content blocks of file.
BlockSource
implementations must decide if they will be thread-safe,
or not.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
adviseSequentialRead
(long startPos, long endPos) Advise theBlockSource
a sequential scan is starting.abstract void
close()
static BlockSource
from
(byte[] content) Wrap a byte array as aBlockSource
.static BlockSource
from
(FileInputStream in) Read from aFileInputStream
.static BlockSource
from
(FileChannel ch) Read from aFileChannel
.abstract ByteBuffer
read
(long position, int blockSize) Read a block from the file.abstract long
size()
Determine the size of the file.
-
Constructor Details
-
BlockSource
public BlockSource()
-
-
Method Details
-
from
Wrap a byte array as aBlockSource
.- Parameters:
content
- input file.- Returns:
- block source to read from
content
.
-
from
Read from aFileInputStream
.The returned
BlockSource
is not thread-safe, as it must seek the file channel to read a block.- Parameters:
in
- the file. TheBlockSource
will closein
.- Returns:
- wrapper for
in
.
-
from
Read from aFileChannel
.The returned
BlockSource
is not thread-safe, as it must seek the file channel to read a block.- Parameters:
ch
- the file. TheBlockSource
will closech
.- Returns:
- wrapper for
ch
.
-
read
Read a block from the file.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.- Parameters:
position
- position of the block in the file, specified in bytes from the beginning of the file.blockSize
- size to read.- Returns:
- buffer containing the block content.
- Throws:
IOException
- if block cannot be read.
-
size
Determine the size of the file.- Returns:
- total number of bytes in the file.
- Throws:
IOException
- if size cannot be obtained.
-
adviseSequentialRead
public void adviseSequentialRead(long startPos, long endPos) Advise theBlockSource
a sequential scan is starting.- Parameters:
startPos
- starting position.endPos
- ending position.
-
close
public abstract void close()- Specified by:
close
in interfaceAutoCloseable
-