public class DeltaEncoder
extends java.lang.Object
BinaryDelta
.Modifier and Type | Field and Description |
---|---|
private byte[] |
buf |
private int |
limit |
private static int |
MAX_COPY_CMD_SIZE
Maximum number of bytes used by a copy instruction.
|
private static int |
MAX_INSERT_DATA_SIZE
Maximum length that an insert command can encode at once.
|
private static int |
MAX_V2_COPY
Maximum number of bytes to be copied in pack v2 format.
|
private java.io.OutputStream |
out |
private int |
size |
Constructor and Description |
---|
DeltaEncoder(java.io.OutputStream out,
long baseSize,
long resultSize)
Create an encoder with no upper bound on the instruction stream size.
|
DeltaEncoder(java.io.OutputStream out,
long baseSize,
long resultSize,
int limit)
Create an encoder with an upper limit on the instruction size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
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(java.lang.String text)
Insert a literal string of text, in UTF-8 encoding.
|
private void |
writeVarint(long sz) |
private static final int MAX_V2_COPY
Historical limitations have this at 64k, even though current delta decoders recognize larger copy instructions.
private static final int MAX_COPY_CMD_SIZE
private static final int MAX_INSERT_DATA_SIZE
private final java.io.OutputStream out
private final byte[] buf
private final int limit
private int size
public DeltaEncoder(java.io.OutputStream out, long baseSize, long resultSize) throws java.io.IOException
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.java.io.IOException
- the output buffer cannot store the instruction stream's
header with the size fields.public DeltaEncoder(java.io.OutputStream out, long baseSize, long resultSize, int limit) throws java.io.IOException
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.java.io.IOException
- the output buffer cannot store the instruction stream's
header with the size fields.private void writeVarint(long sz) throws java.io.IOException
java.io.IOException
public int getSize()
public boolean insert(java.lang.String text) throws java.io.IOException
text
- the string to insert.java.io.IOException
- the instruction buffer can't store the instructions.public boolean insert(byte[] text) throws java.io.IOException
text
- the binary to insert.java.io.IOException
- the instruction buffer can't store the instructions.public boolean insert(byte[] text, int off, int cnt) throws java.io.IOException
text
- the binary to insert.off
- offset within text
to start copying from.cnt
- number of bytes to insert.java.io.IOException
- the instruction buffer can't store the instructions.public boolean copy(long offset, int cnt) throws java.io.IOException
offset
- position in the base object to copy from. This is absolute,
from the beginning of the base.cnt
- number of bytes to copy.java.io.IOException
- the instruction buffer cannot store the instructions.private int encodeCopy(int p, long offset, int cnt)