Class DfsInserter

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class DfsInserter
    extends ObjectInserter
    Inserts objects into the DFS.
    • Constructor Detail

      • DfsInserter

        protected DfsInserter​(DfsObjDatabase db)
        Initialize a new inserter.
        Parameters:
        db - database the inserter writes to.
    • Method Detail

      • checkExisting

        public void checkExisting​(boolean check)
        Check existence
        Parameters:
        check - if false, will write out possibly-duplicate objects without first checking whether they exist in the repo; default is true.
      • setCompressionLevel

        void setCompressionLevel​(int compression)
      • newPackParser

        public DfsPackParser newPackParser​(java.io.InputStream in)
                                    throws java.io.IOException
        Initialize a parser to read from a pack formatted stream.
        Specified by:
        newPackParser in class ObjectInserter
        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 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.

        Specified by:
        newReader in class ObjectInserter
        Returns:
        reader for any object, including an object recently inserted by this inserter since the last flush.
      • 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:
        insert in class ObjectInserter
        Parameters:
        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.
        Returns:
        the name of the object.
        Throws:
        java.io.IOException - the object could not be stored.
      • insert

        public ObjectId insert​(int type,
                               long len,
                               java.io.InputStream in)
                        throws java.io.IOException
        Insert a single object into the store, returning its unique name.
        Specified by:
        insert in class ObjectInserter
        Parameters:
        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.
        Returns:
        the name of the object.
        Throws:
        java.io.IOException - the object could not be stored, or the source stream could not be read.
      • insertBuffer

        private byte[] insertBuffer​(long len)
      • flush

        public void flush()
                   throws java.io.IOException
        Make all inserted objects visible.

        The flush may take some period of time to make the objects available to other threads.

        Specified by:
        flush in class ObjectInserter
        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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class ObjectInserter
      • clear

        private void clear()
      • beginObject

        private long beginObject​(int type,
                                 long len)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • beginPack

        private void beginPack()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sortObjectsById

        private void sortObjectsById()
      • index

        private static void index​(java.io.OutputStream out,
                                  byte[] packHash,
                                  java.util.List<PackedObjectInfo> list)
                           throws java.io.IOException
        Throws:
        java.io.IOException