class ObjectDirectoryInserter extends ObjectInserter
ObjectDirectory
.Modifier and Type | Class and Description |
---|---|
private static class |
ObjectDirectoryInserter.SHA1OutputStream |
ObjectInserter.Filter, ObjectInserter.Formatter
Modifier and Type | Field and Description |
---|---|
private WriteConfig |
config |
private FileObjectDatabase |
db |
private java.util.zip.Deflater |
deflate |
Constructor and Description |
---|
ObjectDirectoryInserter(FileObjectDatabase dest,
Config cfg) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
(package private) java.util.zip.DeflaterOutputStream |
compress(java.io.OutputStream out) |
void |
flush()
Make all inserted objects visible.
|
ObjectId |
insert(int type,
byte[] data,
int off,
int len)
Insert a single object into the store, returning its unique name.
|
private ObjectId |
insert(int type,
byte[] data,
int off,
int len,
boolean createDuplicate)
Insert a loose object into the database.
|
ObjectId |
insert(int type,
long len,
java.io.InputStream is)
Insert a single object into the store, returning its unique name.
|
(package private) ObjectId |
insert(int type,
long len,
java.io.InputStream is,
boolean createDuplicate)
Insert a loose object into the database.
|
private ObjectId |
insertOneObject(java.io.File tmp,
ObjectId id,
boolean createDuplicate) |
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.
|
(package private) java.io.File |
newTempFile() |
private static java.io.EOFException |
shortInput(long missing) |
private java.io.File |
toTemp(int type,
byte[] buf,
int pos,
int len) |
private java.io.File |
toTemp(SHA1 md,
int type,
long len,
java.io.InputStream is) |
(package private) void |
writeHeader(java.io.OutputStream out,
int type,
long len) |
private final FileObjectDatabase db
private final WriteConfig config
private java.util.zip.Deflater deflate
ObjectDirectoryInserter(FileObjectDatabase dest, Config cfg)
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.private ObjectId insert(int type, byte[] data, int off, int len, boolean createDuplicate) throws java.io.IOException
type
- data
- off
- len
- createDuplicate
- java.io.IOException
public ObjectId insert(int type, long len, java.io.InputStream is) throws java.io.IOException
insert
in class ObjectInserter
type
- type code of the object to store.len
- number of bytes to copy from in
.is
- 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.ObjectId insert(int type, long len, java.io.InputStream is, boolean createDuplicate) throws java.io.IOException
type
- len
- is
- createDuplicate
- java.io.IOException
private ObjectId insertOneObject(java.io.File tmp, ObjectId id, boolean createDuplicate) throws java.io.IOException, ObjectWritingException
java.io.IOException
ObjectWritingException
public PackParser newPackParser(java.io.InputStream in) throws java.io.IOException
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.java.io.IOException
- the parser instance, which can be configured and then used to
parse objects into the ObjectDatabase.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.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 java.io.File toTemp(SHA1 md, int type, long len, java.io.InputStream is) throws java.io.IOException, java.io.FileNotFoundException, java.lang.Error
java.io.IOException
java.io.FileNotFoundException
java.lang.Error
private java.io.File toTemp(int type, byte[] buf, int pos, int len) throws java.io.IOException, java.io.FileNotFoundException
java.io.IOException
java.io.FileNotFoundException
void writeHeader(java.io.OutputStream out, int type, long len) throws java.io.IOException
java.io.IOException
java.io.File newTempFile() throws java.io.IOException
java.io.IOException
java.util.zip.DeflaterOutputStream compress(java.io.OutputStream out)
private static java.io.EOFException shortInput(long missing)