Top Description Constructors Methods
org.eclipse.jgit.internal.storage.io

public abstract Class BlockSource

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Known Direct Subclasses
org.eclipse.jgit.internal.storage.dfs.DfsReftable.CacheSource
Imports
java.io.FileInputStream, .IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel

Provides content blocks of file.

BlockSource implementations must decide if they will be thread-safe, or not.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
adviseSequentialRead(long
starting position.
startPos
,
long
ending position.
endPos
)

Advise the BlockSource a sequential scan is starting.

public abstract void
close()

Redeclares java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public static BlockSource

Returns:

block source to read from content.
from
(byte[]
input file.
content
)

Wrap a byte array as a BlockSource.

public static BlockSource

Returns:

wrapper for in.
from
(FileInputStream
the file. The BlockSource will close in.
in
)

Read from a FileInputStream.

public static BlockSource

Returns:

wrapper for ch.
from
(FileChannel
the file. The BlockSource will close ch.
ch
)

Read from a FileChannel.

public abstract ByteBuffer

Returns:

buffer containing the block content.
read
(long
position of the block in the file, specified in bytes from the beginning of the file.
position
,
int
size to read.
blockSize
)

Read a block from the file.

public abstract long

Returns:

total number of bytes in the file.
size
()

Determine the size of the file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BlockSourceback to summary
public BlockSource()

Method Detail

adviseSequentialReadback to summary
public void adviseSequentialRead(long startPos, long endPos)

Advise the BlockSource a sequential scan is starting.

Parameters
startPos:long

starting position.

endPos:long

ending position.

closeback to summary
public abstract void close()

Redeclares java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
fromback to summary
public static BlockSource from(byte[] content)

Wrap a byte array as a BlockSource.

Parameters
content:byte[]

input file.

Returns:BlockSource

block source to read from content.

fromback to summary
public static BlockSource from(FileInputStream in)

Read from a FileInputStream.

The returned BlockSource is not thread-safe, as it must seek the file channel to read a block.

Parameters
in:FileInputStream

the file. The BlockSource will close in.

Returns:BlockSource

wrapper for in.

fromback to summary
public static BlockSource from(FileChannel ch)

Read from a FileChannel.

The returned BlockSource is not thread-safe, as it must seek the file channel to read a block.

Parameters
ch:FileChannel

the file. The BlockSource will close ch.

Returns:BlockSource

wrapper for ch.

readback to summary
public abstract ByteBuffer read(long position, int blockSize) throws IOException

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:long

position of the block in the file, specified in bytes from the beginning of the file.

blockSize:int

size to read.

Returns:ByteBuffer

buffer containing the block content.

Exceptions
IOException:
if block cannot be read.
sizeback to summary
public abstract long size() throws IOException

Determine the size of the file.

Returns:long

total number of bytes in the file.

Exceptions
IOException:
if size cannot be obtained.