Class ObjectDirectoryInserter
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectInserter
-
- org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
class ObjectDirectoryInserter extends ObjectInserter
Creates loose objects in aObjectDirectory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classObjectDirectoryInserter.SHA1OutputStream-
Nested classes/interfaces inherited from class org.eclipse.jgit.lib.ObjectInserter
ObjectInserter.Filter, ObjectInserter.Formatter
-
-
Field Summary
Fields Modifier and Type Field Description private WriteConfigconfigprivate FileObjectDatabasedbprivate java.util.zip.Deflaterdeflate
-
Constructor Summary
Constructors Constructor Description ObjectDirectoryInserter(FileObjectDatabase dest, Config cfg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()(package private) java.util.zip.DeflaterOutputStreamcompress(java.io.OutputStream out)voidflush()Make all inserted objects visible.ObjectIdinsert(int type, byte[] data, int off, int len)Insert a single object into the store, returning its unique name.private ObjectIdinsert(int type, byte[] data, int off, int len, boolean createDuplicate)Insert a loose object into the database.ObjectIdinsert(int type, long len, java.io.InputStream is)Insert a single object into the store, returning its unique name.(package private) ObjectIdinsert(int type, long len, java.io.InputStream is, boolean createDuplicate)Insert a loose object into the database.private ObjectIdinsertOneObject(java.io.File tmp, ObjectId id, boolean createDuplicate)PackParsernewPackParser(java.io.InputStream in)Initialize a parser to read from a pack formatted stream.ObjectReadernewReader()Open a reader for objects that may have been written by this inserter.(package private) java.io.FilenewTempFile()private static java.io.EOFExceptionshortInput(long missing)private java.io.FiletoTemp(int type, byte[] buf, int pos, int len)private java.io.FiletoTemp(SHA1 md, int type, long len, java.io.InputStream is)(package private) voidwriteHeader(java.io.OutputStream out, int type, long len)
-
-
-
Field Detail
-
db
private final FileObjectDatabase db
-
config
private final WriteConfig config
-
deflate
private java.util.zip.Deflater deflate
-
-
Constructor Detail
-
ObjectDirectoryInserter
ObjectDirectoryInserter(FileObjectDatabase dest, Config cfg)
-
-
Method Detail
-
insert
public ObjectId insert(int type, byte[] data, int off, int len) throws java.io.IOException
Insert a single object into the store, returning its unique name.- Overrides:
insertin classObjectInserter- 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:
java.io.IOException- the object could not be stored.
-
insert
private ObjectId insert(int type, byte[] data, int off, int len, boolean createDuplicate) throws java.io.IOException
Insert a loose object into the database. If createDuplicate is true, write the loose object even if we already have it in the loose or packed ODB.- Parameters:
type-data-off-len-createDuplicate-- Returns:
- ObjectId
- Throws:
java.io.IOException
-
insert
public ObjectId insert(int type, long len, java.io.InputStream is) throws java.io.IOException
Insert a single object into the store, returning its unique name.- Specified by:
insertin classObjectInserter- Parameters:
type- type code of the object to store.len- number of bytes to copy fromin.is- stream providing the object content. The caller is responsible for closing the stream.- Returns:
- the name of the object.
- Throws:
java.io.IOException- the object could not be stored, or the source stream could not be read.
-
insert
ObjectId insert(int type, long len, java.io.InputStream is, boolean createDuplicate) throws java.io.IOException
Insert a loose object into the database. If createDuplicate is true, write the loose object even if we already have it in the loose or packed ODB.- Parameters:
type-len-is-createDuplicate-- Returns:
- ObjectId
- Throws:
java.io.IOException
-
insertOneObject
private ObjectId insertOneObject(java.io.File tmp, ObjectId id, boolean createDuplicate) throws java.io.IOException
- Throws:
java.io.IOException
-
newPackParser
public PackParser newPackParser(java.io.InputStream in) throws java.io.IOException
Initialize a parser to read from a pack formatted stream.- Specified by:
newPackParserin classObjectInserter- 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:
java.io.IOException- the parser instance, which can be configured and then used to parse objects into the ObjectDatabase.
-
newReader
public ObjectReader 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
ObjectStreamopened 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.- Specified by:
newReaderin classObjectInserter- Returns:
- reader for any object, including an object recently inserted by this inserter since the last flush.
-
flush
public void flush() throws java.io.IOExceptionMake all inserted objects visible.The flush may take some period of time to make the objects available to other threads.
- Specified by:
flushin classObjectInserter- Throws:
java.io.IOException- the flush could not be completed; objects inserted thus far are in an indeterminate state.
-
close
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.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein classObjectInserter
-
toTemp
private java.io.File toTemp(SHA1 md, int type, long len, java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
toTemp
private java.io.File toTemp(int type, byte[] buf, int pos, int len) throws java.io.IOException- Throws:
java.io.IOException
-
writeHeader
void writeHeader(java.io.OutputStream out, int type, long len) throws java.io.IOException- Throws:
java.io.IOException
-
newTempFile
java.io.File newTempFile() throws java.io.IOException- Throws:
java.io.IOException
-
compress
java.util.zip.DeflaterOutputStream compress(java.io.OutputStream out)
-
shortInput
private static java.io.EOFException shortInput(long missing)
-
-