Top Description Fields Constructors Methods
org.eclipse.jgit.internal.storage.pack

public Class DeltaEncoder

extends Object
Class Inheritance
Imports
java.io.IOException, .OutputStream, org.eclipse.jgit.lib.Constants

Encodes an instruction stream for org.eclipse.jgit.internal.storage.pack.BinaryDelta.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int
private static final int
MAX_COPY_CMD_SIZE

Maximum number of bytes used by a copy instruction.

private static final int
MAX_INSERT_DATA_SIZE

Maximum length that an insert command can encode at once.

private static final int
MAX_V2_COPY

Maximum number of bytes to be copied in pack v2 format.

private final OutputStream
private int

Constructor Summary

AccessConstructor and Description
public
DeltaEncoder(OutputStream
buffer to store the instructions written.
out
,
long
size of the base object, in bytes.
baseSize
,
long
size of the resulting object, after applying this instruction stream to the base object, in bytes.
resultSize
)

Create an encoder with no upper bound on the instruction stream size.

public
DeltaEncoder(OutputStream
buffer to store the instructions written.
out
,
long
size of the base object, in bytes.
baseSize
,
long
size of the resulting object, after applying this instruction stream to the base object, in bytes.
resultSize
,
int
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.
limit
)

Create an encoder with an upper limit on the instruction size.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the copy fits within the limit; false if the copy would cause the instruction stream to exceed the limit.
copy
(long
position in the base object to copy from. This is absolute, from the beginning of the base.
offset
,
int
number of bytes to copy.
cnt
)

Create a copy instruction to copy from the base object.

private int
encodeCopy(int p, long offset, int cnt)

public int

Returns:

current size of the delta stream, in bytes.
getSize
()

Get current size of the delta stream, in bytes.

public boolean

Returns:

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
insert
(String
the string to insert.
text
)

Insert a literal string of text, in UTF-8 encoding.

public boolean

Returns:

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
insert
(byte[]
the binary to insert.
text
)

Insert a literal binary sequence.

public boolean

Returns:

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.
insert
(byte[]
the binary to insert.
text
,
int
offset within text to start copying from.
off
,
int
number of bytes to insert.
cnt
)

Insert a literal binary sequence.

private void
writeVarint(long sz)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private final byte[] buf
limitback to summary
private final int limit
MAX_COPY_CMD_SIZEback to summary
private static final int MAX_COPY_CMD_SIZE

Maximum number of bytes used by a copy instruction.

MAX_INSERT_DATA_SIZEback to summary
private static final int MAX_INSERT_DATA_SIZE

Maximum length that an insert command can encode at once.

MAX_V2_COPYback to summary
private static final int MAX_V2_COPY

Maximum 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.

outback to summary
private final OutputStream out
sizeback to summary
private int size

Constructor Detail

DeltaEncoderback to summary
public DeltaEncoder(OutputStream out, long baseSize, long resultSize) throws IOException

Create an encoder with no upper bound on the instruction stream size.

Parameters
out:OutputStream

buffer to store the instructions written.

baseSize:long

size of the base object, in bytes.

resultSize:long

size of the resulting object, after applying this instruction stream to the base object, in bytes.

Exceptions
IOException:
the output buffer cannot store the instruction stream's header with the size fields.
DeltaEncoderback to summary
public DeltaEncoder(OutputStream out, long baseSize, long resultSize, int limit) throws IOException

Create an encoder with an upper limit on the instruction size.

Parameters
out:OutputStream

buffer to store the instructions written.

baseSize:long

size of the base object, in bytes.

resultSize:long

size of the resulting object, after applying this instruction stream to the base object, in bytes.

limit:int

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.

Exceptions
IOException:
the output buffer cannot store the instruction stream's header with the size fields.

Method Detail

copyback to summary
public boolean copy(long offset, int cnt) throws IOException

Create a copy instruction to copy from the base object.

Parameters
offset:long

position in the base object to copy from. This is absolute, from the beginning of the base.

cnt:int

number of bytes to copy.

Returns:boolean

true if the copy fits within the limit; false if the copy would cause the instruction stream to exceed the limit.

Exceptions
IOException:
the instruction buffer cannot store the instructions.
encodeCopyback to summary
private int encodeCopy(int p, long offset, int cnt)
getSizeback to summary
public int getSize()

Get current size of the delta stream, in bytes.

Returns:int

current size of the delta stream, in bytes.

insertback to summary
public boolean insert(String text) throws IOException

Insert a literal string of text, in UTF-8 encoding.

Parameters
text:String

the string to insert.

Returns:boolean

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.

Exceptions
IOException:
the instruction buffer can't store the instructions.
insertback to summary
public boolean insert(byte[] text) throws IOException

Insert a literal binary sequence.

Parameters
text:byte[]

the binary to insert.

Returns:boolean

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.

Exceptions
IOException:
the instruction buffer can't store the instructions.
insertback to summary
public boolean insert(byte[] text, int off, int cnt) throws IOException

Insert a literal binary sequence.

Parameters
text:byte[]

the binary to insert.

off:int

offset within text to start copying from.

cnt:int

number of bytes to insert.

Returns:boolean

true if the insert fits within the limit; false if the insert would cause the instruction stream to exceed the limit.

Exceptions
IOException:
the instruction buffer can't store the instructions.
writeVarintback to summary
private void writeVarint(long sz) throws IOException