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.
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private int | |
| private final InputStream | |
| private int | |
| private int | |
| private long | |
| private long |
| Access | Constructor and Description |
|---|---|
| public | BinaryDeltaInputStream(byte[]
data to apply the delta to base, InputStream InputStream delivering the delta to applyCreates a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
| public long | |
| private void | |
| public boolean | Returns: whether delta application was successfulTells whether the delta has been fully consumed, and the expected number
of bytes for the combined result have been read from this
|
| private int | |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public int | read(byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
| private int | |
| private long |
| base | back to summary |
|---|---|
| private final byte[] base | |
| baseOffset | back to summary |
|---|---|
| private int baseOffset | |
| delta | back to summary |
|---|---|
| private final InputStream delta | |
| fromBase | back to summary |
|---|---|
| private int fromBase | |
| fromDelta | back to summary |
|---|---|
| private int fromDelta | |
| resultLength | back to summary |
|---|---|
| private long resultLength | |
| toDeliver | back to summary |
|---|---|
| private long toDeliver | |
| BinaryDeltaInputStream | back to summary |
|---|---|
| public BinaryDeltaInputStream(byte[] base, InputStream delta) Creates a new
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| getExpectedResultSize | back to summary |
|---|---|
| public long getExpectedResultSize() throws IOException Tells the expected size of the final result.
| |
| initialize | back to summary |
|---|---|
| private void initialize() throws IOException | |
| isFullyConsumed | back to summary |
|---|---|
| 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 this
| |
| next | back to summary |
|---|---|
| private int next(InputStream in) throws IOException | |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| readNext | back to summary |
|---|---|
| private int readNext() throws IOException | |
| readVarInt | back to summary |
|---|---|
| private long readVarInt(InputStream in) throws IOException | |