Class DeltaEncoder
java.lang.Object
org.eclipse.jgit.internal.storage.pack.DeltaEncoder
Encodes an instruction stream for
BinaryDelta
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
private final int
private static final int
Maximum number of bytes used by a copy instruction.private static final int
Maximum length that an insert command can encode at once.private static final int
Maximum number of bytes to be copied in pack v2 format.private final OutputStream
private int
-
Constructor Summary
ConstructorsConstructorDescriptionDeltaEncoder
(OutputStream out, long baseSize, long resultSize) Create an encoder with no upper bound on the instruction stream size.DeltaEncoder
(OutputStream out, long baseSize, long resultSize, int limit) Create an encoder with an upper limit on the instruction size. -
Method Summary
Modifier and TypeMethodDescriptionboolean
copy
(long offset, int cnt) Create a copy instruction to copy from the base object.private int
encodeCopy
(int p, long offset, int cnt) int
getSize()
Get current size of the delta stream, in bytes.boolean
insert
(byte[] text) Insert a literal binary sequence.boolean
insert
(byte[] text, int off, int cnt) Insert a literal binary sequence.boolean
Insert a literal string of text, in UTF-8 encoding.private void
writeVarint
(long sz)
-
Field Details
-
MAX_V2_COPY
private static final int MAX_V2_COPYMaximum number of bytes to be copied in pack v2 format.Historical limitations have this at 64k, even though current delta decoders recognize larger copy instructions.
- See Also:
-
MAX_COPY_CMD_SIZE
private static final int MAX_COPY_CMD_SIZEMaximum number of bytes used by a copy instruction.- See Also:
-
MAX_INSERT_DATA_SIZE
private static final int MAX_INSERT_DATA_SIZEMaximum length that an insert command can encode at once.- See Also:
-
out
-
buf
private final byte[] buf -
limit
private final int limit -
size
private int size
-
-
Constructor Details
-
DeltaEncoder
Create an encoder with no upper bound on the instruction stream size.- Parameters:
out
- buffer to store the instructions written.baseSize
- size of the base object, in bytes.resultSize
- size of the resulting object, after applying this instruction stream to the base object, in bytes.- Throws:
IOException
- the output buffer cannot store the instruction stream's header with the size fields.
-
DeltaEncoder
Create an encoder with an upper limit on the instruction size.- Parameters:
out
- buffer to store the instructions written.baseSize
- size of the base object, in bytes.resultSize
- size of the resulting object, after applying this instruction stream to the base object, in bytes.limit
- maximum number of bytes to write to the out buffer declaring the stream is over limit and should be discarded. May be 0 to specify an infinite limit.- Throws:
IOException
- the output buffer cannot store the instruction stream's header with the size fields.
-
-
Method Details
-
writeVarint
- Throws:
IOException
-
getSize
public int getSize()Get current size of the delta stream, in bytes.- Returns:
- current size of the delta stream, in bytes.
-
insert
Insert a literal string of text, in UTF-8 encoding.- Parameters:
text
- the string to insert.- Returns:
- true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
- Throws:
IOException
- the instruction buffer can't store the instructions.
-
insert
Insert a literal binary sequence.- Parameters:
text
- the binary to insert.- Returns:
- true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
- Throws:
IOException
- the instruction buffer can't store the instructions.
-
insert
Insert a literal binary sequence.- Parameters:
text
- the binary to insert.off
- offset withintext
to start copying from.cnt
- number of bytes to insert.- Returns:
- true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
- Throws:
IOException
- the instruction buffer can't store the instructions.
-
copy
Create a copy instruction to copy from the base object.- Parameters:
offset
- position in the base object to copy from. This is absolute, from the beginning of the base.cnt
- number of bytes to copy.- Returns:
- true if the copy fits within the limit; false if the copy would cause the instruction stream to exceed the limit.
- Throws:
IOException
- the instruction buffer cannot store the instructions.
-
encodeCopy
private int encodeCopy(int p, long offset, int cnt)
-