public class DfsPackParser extends PackParser
PackParser.ObjectTypeAndSize, PackParser.Source, PackParser.UnresolvedDelta
Modifier | Constructor and Description |
---|---|
protected |
DfsPackParser(DfsObjDatabase db,
DfsInserter ins,
InputStream in)
Initialize a new pack parser.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkCRC(int oldCRC)
Check the current CRC matches the expected value.
|
DfsPackDescription |
getPackDescription()
Get description of the imported pack, if one was made.
|
protected boolean |
onAppendBase(int typeCode,
byte[] data,
PackedObjectInfo info)
Provide the implementation with a base that was outside of the pack.
|
protected void |
onBeginOfsDelta(long streamPosition,
long baseStreamPosition,
long inflatedSize)
Event notifying start of a delta referencing its base by offset.
|
protected void |
onBeginRefDelta(long streamPosition,
AnyObjectId baseId,
long inflatedSize)
Event notifying start of a delta referencing its base by ObjectId.
|
protected void |
onBeginWholeObject(long streamPosition,
int type,
long inflatedSize)
Event notifying the start of an object stored whole (not as a delta).
|
protected PackParser.UnresolvedDelta |
onEndDelta()
Event notifying the the current object.
|
protected void |
onEndThinPack()
Event indicating a thin pack has been completely processed.
|
protected void |
onEndWholeObject(PackedObjectInfo info)
Event notifying the the current object.
|
protected void |
onInflatedObjectData(PackedObjectInfo obj,
int typeCode,
byte[] data)
Invoked for commits, trees, tags, and small blobs.
|
protected void |
onObjectData(PackParser.Source src,
byte[] raw,
int pos,
int len)
Store (and/or checksum) a portion of an object's data.
|
protected void |
onObjectHeader(PackParser.Source src,
byte[] raw,
int pos,
int len)
Store (and/or checksum) an object header.
|
protected void |
onPackFooter(byte[] hash)
Provide the implementation with the original stream's pack footer.
|
protected void |
onPackHeader(long objectCount)
Provide the implementation with the original stream's pack header.
|
protected void |
onStoreStream(byte[] raw,
int pos,
int len)
Store bytes received from the raw stream.
|
PackLock |
parse(ProgressMonitor receiving,
ProgressMonitor resolving)
Parse the pack stream.
|
protected int |
readDatabase(byte[] dst,
int pos,
int cnt)
Read from the database's current position into the buffer.
|
protected PackParser.ObjectTypeAndSize |
seekDatabase(PackedObjectInfo obj,
PackParser.ObjectTypeAndSize info)
Reposition the database to re-read a previously stored object.
|
protected PackParser.ObjectTypeAndSize |
seekDatabase(PackParser.UnresolvedDelta delta,
PackParser.ObjectTypeAndSize info)
Reposition the database to re-read a previously stored object.
|
buffer, getBaseObjectIds, getLockMessage, getNewObjectIds, getObject, getObjectCount, getPackSize, getReceivedPackStatistics, getSortedObjectList, isAllowThin, isCheckEofAfterPackFooter, isCheckObjectCollisions, isExpectDataAfterPackFooter, newInfo, parse, readObjectHeader, setAllowThin, setCheckEofAfterPackFooter, setCheckObjectCollisions, setExpectDataAfterPackFooter, setExpectedObjectCount, setLockMessage, setMaxObjectSizeLimit, setNeedBaseObjectIds, setNeedNewObjectIds, setObjectChecker, setObjectChecking, verifySafeObject
protected DfsPackParser(DfsObjDatabase db, DfsInserter ins, InputStream in)
db
- database the objects will be imported into.ins
- inserter the parser will use to help it inject the objects.in
- the stream to parse.public PackLock parse(ProgressMonitor receiving, ProgressMonitor resolving) throws IOException
parse
in class PackParser
receiving
- receives progress feedback during the initial receiving
objects phase. If null,
NullProgressMonitor
will be used.resolving
- receives progress feedback during the resolving objects phase.PackParser.setLockMessage(String)
.IOException
- the stream is malformed, or contains corrupt objects.public DfsPackDescription getPackDescription()
protected void onPackHeader(long objectCount) throws IOException
onPackHeader
in class PackParser
objectCount
- number of objects expected in the stream.IOException
- the implementation refuses to work with this many objects.protected void onBeginWholeObject(long streamPosition, int type, long inflatedSize) throws IOException
onBeginWholeObject
in class PackParser
streamPosition
- position of this object in the incoming stream.type
- type of the object; one of
Constants.OBJ_COMMIT
,
Constants.OBJ_TREE
,
Constants.OBJ_BLOB
, or
Constants.OBJ_TAG
.inflatedSize
- size of the object when fully inflated. The size stored within
the pack may be larger or smaller, and is not yet known.IOException
- the object cannot be recorded.protected void onEndWholeObject(PackedObjectInfo info) throws IOException
onEndWholeObject
in class PackParser
info
- object information.IOException
- the object cannot be recorded.protected void onBeginOfsDelta(long streamPosition, long baseStreamPosition, long inflatedSize) throws IOException
onBeginOfsDelta
in class PackParser
streamPosition
- position of this object in the incoming stream.baseStreamPosition
- position of the base object in the incoming stream. The base
must be before the delta, therefore baseStreamPosition
< deltaStreamPosition
. This is not the position
returned by a prior end object event.inflatedSize
- size of the delta when fully inflated. The size stored within
the pack may be larger or smaller, and is not yet known.IOException
- the object cannot be recorded.protected void onBeginRefDelta(long streamPosition, AnyObjectId baseId, long inflatedSize) throws IOException
onBeginRefDelta
in class PackParser
streamPosition
- position of this object in the incoming stream.baseId
- name of the base object. This object may be later in the
stream, or might not appear at all in the stream (in the case
of a thin-pack).inflatedSize
- size of the delta when fully inflated. The size stored within
the pack may be larger or smaller, and is not yet known.IOException
- the object cannot be recorded.protected PackParser.UnresolvedDelta onEndDelta() throws IOException
onEndDelta
in class PackParser
IOException
- the object cannot be recorded.protected void onInflatedObjectData(PackedObjectInfo obj, int typeCode, byte[] data) throws IOException
onInflatedObjectData
in class PackParser
obj
- the object info, populated.typeCode
- the type of the object.data
- inflated data for the object.IOException
- the object cannot be archived.protected void onObjectHeader(PackParser.Source src, byte[] raw, int pos, int len) throws IOException
Invoked after any of the onBegin()
events. The entire header is
supplied in a single invocation, before any object data is supplied.
onObjectHeader
in class PackParser
src
- where the data came fromraw
- buffer to read data from.pos
- first offset within buffer that is valid.len
- number of bytes in buffer that are valid.IOException
- the stream cannot be archived.protected void onObjectData(PackParser.Source src, byte[] raw, int pos, int len) throws IOException
This method may be invoked multiple times per object, depending on the size of the object, the size of the parser's internal read buffer, and the alignment of the object relative to the read buffer.
Invoked after PackParser.onObjectHeader(Source, byte[], int, int)
.
onObjectData
in class PackParser
src
- where the data came fromraw
- buffer to read data from.pos
- first offset within buffer that is valid.len
- number of bytes in buffer that are valid.IOException
- the stream cannot be archived.protected void onStoreStream(byte[] raw, int pos, int len) throws IOException
This method is invoked during PackParser.parse(ProgressMonitor)
as data is
consumed from the incoming stream. Implementors may use this event to
archive the raw incoming stream to the destination repository in large
chunks, without paying attention to object boundaries.
The only component of the pack not supplied to this method is the last 20
bytes of the pack that comprise the trailing SHA-1 checksum. Those are
passed to PackParser.onPackFooter(byte[])
.
onStoreStream
in class PackParser
raw
- buffer to copy data out of.pos
- first offset within the buffer that is valid.len
- number of bytes in the buffer that are valid.IOException
- the stream cannot be archived.protected void onPackFooter(byte[] hash) throws IOException
onPackFooter
in class PackParser
hash
- the trailing 20 bytes of the pack, this is a SHA-1 checksum of
all of the pack data.IOException
- the stream cannot be archived.protected PackParser.ObjectTypeAndSize seekDatabase(PackedObjectInfo obj, PackParser.ObjectTypeAndSize info) throws IOException
If the database is computing CRC-32 checksums for object data, it should reset its internal CRC instance during this method call.
seekDatabase
in class PackParser
obj
- the object position to begin reading from. This is from
PackParser.newInfo(AnyObjectId, UnresolvedDelta, ObjectId)
.info
- object to populate with type and size.info
object.IOException
- the database cannot reposition to this location.protected PackParser.ObjectTypeAndSize seekDatabase(PackParser.UnresolvedDelta delta, PackParser.ObjectTypeAndSize info) throws IOException
If the database is computing CRC-32 checksums for object data, it should reset its internal CRC instance during this method call.
seekDatabase
in class PackParser
delta
- the object position to begin reading from. This is an instance
previously returned by PackParser.onEndDelta()
.info
- object to populate with type and size.info
object.IOException
- the database cannot reposition to this location.protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException
readDatabase
in class PackParser
dst
- the buffer to copy read data into.pos
- position within dst
to start copying data into.cnt
- ideal target number of bytes to read. Actual read length may
be shorter.IOException
- the database cannot be accessed.protected boolean checkCRC(int oldCRC)
This method is invoked when an object is read back in from the database and its data is used during delta resolution. The CRC is validated after the object has been fully read, allowing the parser to verify there was no silent data corruption.
Implementations are free to ignore this check by always returning true if they are performing other data integrity validations at a lower level.
checkCRC
in class PackParser
oldCRC
- the prior CRC that was recorded during the first scan of the
object from the pack stream.protected boolean onAppendBase(int typeCode, byte[] data, PackedObjectInfo info) throws IOException
This event only occurs on a thin pack for base objects that were outside of the pack and came from the local repository. Usually an implementation uses this event to compress the base and append it onto the end of the pack, so the pack stays self-contained.
onAppendBase
in class PackParser
typeCode
- type of the base object.data
- complete content of the base object.info
- packed object information for this base. Implementors must
populate the CRC and offset members if returning true.info
should be included in the object list
returned by PackParser.getSortedObjectList(Comparator)
, false if it
should not be included.IOException
- the base could not be included into the pack.protected void onEndThinPack() throws IOException
This event is invoked only if a thin pack has delta references to objects external from the pack. The event is called after all of those deltas have been resolved.
onEndThinPack
in class PackParser
IOException
- the pack cannot be archived.Copyright © 2018 Eclipse JGit Project. All rights reserved.