Class BinaryDeltaInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
InputStream
that applies a binary delta to a base on the fly.
Delta application to a base needs random access to the base data. The delta is expressed as a sequence of copy and insert instructions. A copy instruction has the form "COPY fromOffset length" and says "copy length bytes from the base, starting at offset fromOffset, to the result". An insert instruction has the form "INSERT length" followed by length bytes and says "copy the next length bytes from the delta to the result".
These instructions are generated using a content-defined chunking algorithm (currently C git uses the standard Rabin variant; but there are others that could be used) that identifies equal chunks. It is entirely possible that a later copy instruction has a fromOffset that is before the fromOffset of an earlier copy instruction.
This makes it impossible to stream the base.
JGit is limited to 2GB maximum size for the base since array indices are signed 32bit values.
- Since:
- 5.12
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
private int
private final InputStream
private int
private int
private long
private long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
long
Tells the expected size of the final result.private void
boolean
Tells whether the delta has been fully consumed, and the expected number of bytes for the combined result have been read from thisBinaryDeltaInputStream
.private int
next
(InputStream in) int
read()
int
read
(byte[] b, int off, int len) private int
readNext()
private long
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
base
private final byte[] base -
delta
-
resultLength
private long resultLength -
toDeliver
private long toDeliver -
fromBase
private int fromBase -
fromDelta
private int fromDelta -
baseOffset
private int baseOffset
-
-
Constructor Details
-
BinaryDeltaInputStream
- Parameters:
base
- data to apply the delta todelta
-InputStream
delivering the delta to apply
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
initialize
- Throws:
IOException
-
readNext
- Throws:
IOException
-
next
- Throws:
IOException
-
readVarInt
- Throws:
IOException
-
getExpectedResultSize
Tells the expected size of the final result.- Returns:
- the size
- Throws:
IOException
- if the size cannot be determined fromdelta
-
isFullyConsumed
public boolean isFullyConsumed()Tells whether the delta has been fully consumed, and the expected number of bytes for the combined result have been read from thisBinaryDeltaInputStream
.- Returns:
- whether delta application was successful
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-