public abstract class ObjectInserter extends Object
ObjectDatabase
.
An inserter is not thread-safe. Individual threads should each obtain their own unique inserter instance, or must arrange for locking at a higher level to ensure the inserter is in use by no more than one thread at a time.
Objects written by an inserter may not be immediately visible for reading
after the insert method completes. Callers must invoke either
release()
or flush()
prior to updating references or
otherwise making the returned ObjectIds visible to other code.
Modifier and Type | Class and Description |
---|---|
static class |
ObjectInserter.Formatter
An inserter that can be used for formatting and id generation only.
|
Modifier | Constructor and Description |
---|---|
protected |
ObjectInserter()
Create a new inserter for a database.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
buffer() |
protected MessageDigest |
digest() |
abstract void |
flush()
Make all inserted objects visible.
|
ObjectId |
idFor(int type,
byte[] data)
Compute the name of an object, without inserting it.
|
ObjectId |
idFor(int type,
byte[] data,
int off,
int len)
Compute the name of an object, without inserting it.
|
ObjectId |
idFor(int objectType,
long length,
InputStream in)
Compute the name of an object, without inserting it.
|
ObjectId |
idFor(TreeFormatter formatter)
Compute the ObjectId for the given tree without inserting it.
|
ObjectId |
insert(CommitBuilder builder)
Insert a single commit into the store, returning its unique name.
|
ObjectId |
insert(int type,
byte[] data)
Insert a single object into the store, returning its unique name.
|
ObjectId |
insert(int type,
byte[] data,
int off,
int len)
Insert a single object into the store, returning its unique name.
|
abstract ObjectId |
insert(int objectType,
long length,
InputStream in)
Insert a single object into the store, returning its unique name.
|
ObjectId |
insert(TagBuilder builder)
Insert a single annotated tag into the store, returning its unique name.
|
ObjectId |
insert(TreeFormatter formatter)
Insert a single tree into the store, returning its unique name.
|
abstract PackParser |
newPackParser(InputStream in)
Initialize a parser to read from a pack formatted stream.
|
abstract void |
release()
Release any resources used by this inserter.
|
protected byte[] buffer()
protected MessageDigest digest()
public ObjectId idFor(int type, byte[] data)
type
- type code of the object to store.data
- complete content of the object.public ObjectId idFor(int type, byte[] data, int off, int len)
type
- type code of the object to store.data
- complete content of the object.off
- first position within data
.len
- number of bytes to copy from data
.public ObjectId idFor(int objectType, long length, InputStream in) throws IOException
objectType
- type code of the object to store.length
- number of bytes to scan from in
.in
- stream providing the object content. The caller is responsible
for closing the stream.IOException
- the source stream could not be read.public ObjectId idFor(TreeFormatter formatter)
formatter
- public final ObjectId insert(TreeFormatter formatter) throws IOException
formatter
- the formatter containing the proposed tree's data.IOException
- the object could not be stored.public final ObjectId insert(CommitBuilder builder) throws IOException
builder
- the builder containing the proposed commit's data.IOException
- the object could not be stored.public final ObjectId insert(TagBuilder builder) throws IOException
builder
- the builder containing the proposed tag's data.IOException
- the object could not be stored.public ObjectId insert(int type, byte[] data) throws IOException
type
- type code of the object to store.data
- complete content of the object.IOException
- the object could not be stored.public ObjectId insert(int type, byte[] data, int off, int len) throws IOException
type
- type code of the object to store.data
- complete content of the object.off
- first position within data
.len
- number of bytes to copy from data
.IOException
- the object could not be stored.public abstract ObjectId insert(int objectType, long length, InputStream in) throws IOException
objectType
- type code of the object to store.length
- number of bytes to copy from in
.in
- stream providing the object content. The caller is responsible
for closing the stream.IOException
- the object could not be stored, or the source stream could
not be read.public abstract PackParser newPackParser(InputStream in) throws IOException
in
- the input stream. The stream is not closed by the parser, and
must instead be closed by the caller once parsing is complete.IOException
- the parser instance, which can be configured and then used to
parse objects into the ObjectDatabase.public abstract void flush() throws IOException
The flush may take some period of time to make the objects available to other threads.
IOException
- the flush could not be completed; objects inserted thus far
are in an indeterminate state.public abstract void release()
An inserter that has been released can be used again, but may need to be released after the subsequent usage.
Copyright © 2012. All Rights Reserved.