Class ObjectInserter
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DfsInserter
,ObjectDirectoryInserter
,ObjectInserter.Filter
,ObjectInserter.Formatter
,PackInserter
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
close()
or flush()
prior to updating references or
otherwise making the returned ObjectIds visible to other code.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Wraps a delegate ObjectInserter.static class
An inserter that can be used for formatting and id generation only. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SHA1
private byte[]
Temporary working buffer for streaming data through. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
buffer()
Obtain a temporary buffer for use by the ObjectInserter or its subclass.abstract void
close()
protected SHA1
digest()
Compute digest to help compute an ObjectIdabstract void
flush()
Make all inserted objects visible.idFor
(int type, byte[] data) Compute the name of an object, without inserting it.idFor
(int type, byte[] data, int off, int len) Compute the name of an object, without inserting it.idFor
(int objectType, long length, InputStream in) Compute the name of an object, without inserting it.idFor
(TreeFormatter formatter) Compute the ObjectId for the given tree without inserting it.insert
(int type, byte[] data) Insert a single object into the store, returning its unique name.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.final ObjectId
insert
(CommitBuilder builder) Insert a single commit into the store, returning its unique name.final ObjectId
insert
(TagBuilder builder) Insert a single annotated tag into the store, returning its unique name.final ObjectId
insert
(TreeFormatter formatter) Insert a single tree into the store, returning its unique name.abstract PackParser
Initialize a parser to read from a pack formatted stream.abstract ObjectReader
Open a reader for objects that may have been written by this inserter.
-
Field Details
-
hasher
-
tempBuffer
private byte[] tempBufferTemporary working buffer for streaming data through.
-
-
Constructor Details
-
ObjectInserter
protected ObjectInserter()Create a new inserter for a database.
-
-
Method Details
-
buffer
protected byte[] buffer()Obtain a temporary buffer for use by the ObjectInserter or its subclass.This buffer is supplied by the ObjectInserter base class to itself and its subclasses for the purposes of pulling data from a supplied InputStream, passing it through a Deflater, or formatting the canonical format of a small object like a small tree or commit.
This buffer IS NOT for translation such as auto-CRLF or content filtering and must not be used for such purposes.
The returned buffer is small, around a few KiBs, and the size may change between versions of JGit. Callers using this buffer must always check the length of the returned array to ascertain how much space was provided.
There is a single buffer for each ObjectInserter, repeated calls to this method will (usually) always return the same buffer. If the caller needs more than one buffer, or needs a buffer of a larger size, it must manage that buffer on its own.
The buffer is usually on first demand for a buffer.
- Returns:
- a temporary byte array for use by the caller.
-
digest
Compute digest to help compute an ObjectId- Returns:
- digest to help compute an ObjectId
- Since:
- 4.7
-
idFor
Compute the name of an object, without inserting it.- Parameters:
type
- type code of the object to store.data
- complete content of the object.- Returns:
- the name of the object.
-
idFor
Compute the name of an object, without inserting it.- Parameters:
type
- type code of the object to store.data
- complete content of the object.off
- first position withindata
.len
- number of bytes to copy fromdata
.- Returns:
- the name of the object.
-
idFor
Compute the name of an object, without inserting it.- Parameters:
objectType
- type code of the object to store.length
- number of bytes to scan fromin
.in
- stream providing the object content. The caller is responsible for closing the stream.- Returns:
- the name of the object.
- Throws:
IOException
- the source stream could not be read.
-
idFor
Compute the ObjectId for the given tree without inserting it.- Parameters:
formatter
- aTreeFormatter
object.- Returns:
- the computed ObjectId
-
insert
Insert a single tree into the store, returning its unique name.- Parameters:
formatter
- the formatter containing the proposed tree's data.- Returns:
- the name of the tree object.
- Throws:
IOException
- the object could not be stored.
-
insert
Insert a single commit into the store, returning its unique name.- Parameters:
builder
- the builder containing the proposed commit's data.- Returns:
- the name of the commit object.
- Throws:
IOException
- the object could not be stored.
-
insert
Insert a single annotated tag into the store, returning its unique name.- Parameters:
builder
- the builder containing the proposed tag's data.- Returns:
- the name of the tag object.
- Throws:
IOException
- the object could not be stored.
-
insert
Insert a single object into the store, returning its unique name.- Parameters:
type
- type code of the object to store.data
- complete content of the object.- Returns:
- the name of the object.
- Throws:
IOException
- the object could not be stored.
-
insert
Insert a single object into the store, returning its unique name.- Parameters:
type
- type code of the object to store.data
- complete content of the object.off
- first position withindata
.len
- number of bytes to copy fromdata
.- Returns:
- the name of the object.
- Throws:
IOException
- the object could not be stored.
-
insert
Insert a single object into the store, returning its unique name.- Parameters:
objectType
- type code of the object to store.length
- number of bytes to copy fromin
.in
- stream providing the object content. The caller is responsible for closing the stream.- Returns:
- the name of the object.
- Throws:
IOException
- the object could not be stored, or the source stream could not be read.
-
newPackParser
Initialize a parser to read from a pack formatted stream.- Parameters:
in
- the input stream. The stream is not closed by the parser, and must instead be closed by the caller once parsing is complete.- Returns:
- the pack parser.
- Throws:
IOException
- the parser instance, which can be configured and then used to parse objects into the ObjectDatabase.
-
newReader
Open a reader for objects that may have been written by this inserter.The returned reader allows the calling thread to read back recently inserted objects without first calling
flush()
to make them visible to the repository. The returned reader should only be used from the same thread as the inserter. Objects written by this inserter may not be visible tothis.newReader().newReader()
.The returned reader should return this inserter instance from
ObjectReader.getCreatedFromInserter()
.Behavior is undefined if an insert method is called on the inserter in the middle of reading from an
ObjectStream
opened from this reader. For example, reading the remainder of the object may fail, or newly written data may even be corrupted. Interleaving whole object reads (including streaming reads) with inserts is fine, just not interleaving streaming partial object reads with inserts.- Returns:
- reader for any object, including an object recently inserted by this inserter since the last flush.
- Since:
- 3.5
-
flush
Make all inserted objects visible.The flush may take some period of time to make the objects available to other threads.
- Throws:
IOException
- the flush could not be completed; objects inserted thus far are in an indeterminate state.
-
close
public abstract void close()Release any resources used by this inserter.
An inserter that has been released can be used again, but may need to be released after the subsequent usage.
- Specified by:
close
in interfaceAutoCloseable
- Since:
- 4.0
-