public class PackInserter extends ObjectInserter
flush()
, and never
inserts loose objects.Modifier and Type | Class and Description |
---|---|
private class |
PackInserter.PackStream
Stream that writes to a pack file.
|
private class |
PackInserter.Reader |
ObjectInserter.Filter, ObjectInserter.Formatter
Modifier and Type | Field and Description |
---|---|
private java.util.zip.Inflater |
cachedInflater |
private boolean |
checkExisting |
private int |
compression |
private ObjectDirectory |
db |
private static int |
INDEX_VERSION
Always produce version 2 indexes, to get CRC data.
|
private java.util.List<PackedObjectInfo> |
objectList |
private ObjectIdOwnerMap<PackedObjectInfo> |
objectMap |
private PackInserter.PackStream |
packOut |
private PackConfig |
pconfig |
private boolean |
rollback |
private java.io.File |
tmpPack |
Constructor and Description |
---|
PackInserter(ObjectDirectory db) |
Modifier and Type | Method and Description |
---|---|
private long |
beginObject(int type,
long len) |
private void |
beginPack() |
void |
checkExisting(boolean check)
Whether to check if objects exist in the repo
|
private void |
clear() |
void |
close() |
private ObjectId |
computeName(java.util.List<PackedObjectInfo> list) |
private ObjectId |
endObject(ObjectId id,
long offset) |
void |
flush()
Make all inserted objects visible.
|
(package private) int |
getBufferSize() |
private static java.io.File |
idxFor(java.io.File packFile) |
private java.util.zip.Inflater |
inflater() |
ObjectId |
insert(int type,
byte[] data,
int off,
int len)
Insert a single object into the store, returning its unique name.
|
ObjectId |
insert(int type,
long len,
java.io.InputStream in)
Insert a single object into the store, returning its unique name.
|
PackParser |
newPackParser(java.io.InputStream in)
Initialize a parser to read from a pack formatted stream.
|
ObjectReader |
newReader()
Open a reader for objects that may have been written by this inserter.
|
void |
setCompressionLevel(int compression)
Set compression level for zlib deflater.
|
private static int |
writePackHeader(byte[] buf,
int objectCount) |
private static void |
writePackIndex(java.io.File idx,
byte[] packHash,
java.util.List<PackedObjectInfo> list) |
private static final int INDEX_VERSION
private final ObjectDirectory db
private java.util.List<PackedObjectInfo> objectList
private ObjectIdOwnerMap<PackedObjectInfo> objectMap
private boolean rollback
private boolean checkExisting
private int compression
private java.io.File tmpPack
private PackInserter.PackStream packOut
private java.util.zip.Inflater cachedInflater
private PackConfig pconfig
PackInserter(ObjectDirectory db)
public void checkExisting(boolean check)
check
- if false
, will write out possibly-duplicate objects
without first checking whether they exist in the repo; default
is true.public void setCompressionLevel(int compression)
compression
- compression level for zlib deflater.int getBufferSize()
public ObjectId insert(int type, byte[] data, int off, int len) throws java.io.IOException
insert
in class ObjectInserter
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
.java.io.IOException
- the object could not be stored.public ObjectId insert(int type, long len, java.io.InputStream in) throws java.io.IOException
insert
in class ObjectInserter
type
- type code of the object to store.len
- number of bytes to copy from in
.in
- stream providing the object content. The caller is responsible
for closing the stream.java.io.IOException
- the object could not be stored, or the source stream could
not be read.private long beginObject(int type, long len) throws java.io.IOException
java.io.IOException
private static java.io.File idxFor(java.io.File packFile)
private void beginPack() throws java.io.IOException
java.io.IOException
private static int writePackHeader(byte[] buf, int objectCount)
public PackParser newPackParser(java.io.InputStream in)
newPackParser
in class ObjectInserter
in
- the input stream. The stream is not closed by the parser, and
must instead be closed by the caller once parsing is complete.public ObjectReader newReader()
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 to this.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.
newReader
in class ObjectInserter
public void flush() throws java.io.IOException
The flush may take some period of time to make the objects available to other threads.
flush
in class ObjectInserter
java.io.IOException
- the flush could not be completed; objects inserted thus far
are in an indeterminate state.private static void writePackIndex(java.io.File idx, byte[] packHash, java.util.List<PackedObjectInfo> list) throws java.io.IOException
java.io.IOException
private ObjectId computeName(java.util.List<PackedObjectInfo> list)
public 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.
close
in interface java.lang.AutoCloseable
close
in class ObjectInserter
private void clear()
private java.util.zip.Inflater inflater()