Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java69
1 files changed, 61 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
index beb51dc2eb..2334bd4851 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java
@@ -14,6 +14,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
+import java.util.function.Supplier;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.internal.JGitText;
@@ -57,11 +58,10 @@ public abstract class PackBitmapIndex {
* @throws CorruptObjectException
* the stream does not contain a valid pack bitmap index.
*/
- public static PackBitmapIndex open(
- File idxFile, PackIndex packIndex, PackReverseIndex reverseIndex)
+ public static PackBitmapIndex open(File idxFile, PackIndex packIndex,
+ PackReverseIndex reverseIndex)
throws IOException {
- try (SilentFileInputStream fd = new SilentFileInputStream(
- idxFile)) {
+ try (SilentFileInputStream fd = new SilentFileInputStream(idxFile)) {
try {
return read(fd, packIndex, reverseIndex);
} catch (IOException ioe) {
@@ -94,12 +94,44 @@ public abstract class PackBitmapIndex {
* @throws CorruptObjectException
* the stream does not contain a valid pack bitmap index.
*/
- public static PackBitmapIndex read(
- InputStream fd, PackIndex packIndex, PackReverseIndex reverseIndex)
- throws IOException {
+ public static PackBitmapIndex read(InputStream fd, PackIndex packIndex,
+ PackReverseIndex reverseIndex) throws IOException {
return new PackBitmapIndexV1(fd, packIndex, reverseIndex);
}
+ /**
+ * Read an existing pack bitmap index file from a buffered stream.
+ * <p>
+ * The format of the file will be automatically detected and a proper access
+ * implementation for that format will be constructed and returned to the
+ * caller. The file may or may not be held open by the returned instance.
+ *
+ * @param fd
+ * stream to read the bitmap index file from. The stream must be
+ * buffered as some small IOs are performed against the stream.
+ * The caller is responsible for closing the stream.
+ * @param packIndexSupplier
+ * the supplier for pack index for the corresponding pack file.
+ * @param reverseIndexSupplier
+ * the supplier for pack reverse index for the corresponding pack
+ * file.
+ * @param loadParallelRevIndex
+ * whether reverse index should be loaded in parallel
+ * @return a copy of the index in-memory.
+ * @throws java.io.IOException
+ * the stream cannot be read.
+ * @throws CorruptObjectException
+ * the stream does not contain a valid pack bitmap index.
+ */
+ public static PackBitmapIndex read(InputStream fd,
+ SupplierWithIOException<PackIndex> packIndexSupplier,
+ SupplierWithIOException<PackReverseIndex> reverseIndexSupplier,
+ boolean loadParallelRevIndex)
+ throws IOException {
+ return new PackBitmapIndexV1(fd, packIndexSupplier,
+ reverseIndexSupplier, loadParallelRevIndex);
+ }
+
/** Footer checksum applied on the bottom of the pack file. */
byte[] packChecksum;
@@ -121,7 +153,8 @@ public abstract class PackBitmapIndex {
* @throws java.lang.IllegalArgumentException
* when the item is not found.
*/
- public abstract ObjectId getObject(int position) throws IllegalArgumentException;
+ public abstract ObjectId getObject(int position)
+ throws IllegalArgumentException;
/**
* Returns a bitmap containing positions for objects that have the given Git
@@ -161,4 +194,24 @@ public abstract class PackBitmapIndex {
* @return the number of bitmaps in this bitmap index.
*/
public abstract int getBitmapCount();
+
+ /**
+ * Supplier that propagates IOException.
+ *
+ * @param <T>
+ * the return type which is expected from {@link #get()}
+ */
+ @FunctionalInterface
+ public interface SupplierWithIOException<T> {
+ /**
+ * Get result.
+ *
+ * @see Supplier#get()
+ *
+ * @return result
+ * @throws IOException
+ * if an IO error occurred
+ */
+ T get() throws IOException;
+ }
}

Back to the top