Class ObjectInserter.Filter

  • Enclosing class:
    ObjectInserter

    public abstract static class ObjectInserter.Filter
    extends ObjectInserter
    Wraps a delegate ObjectInserter.
    • Constructor Summary

      Constructors 
      Constructor Description
      Filter()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected byte[] buffer()
      Obtain a temporary buffer for use by the ObjectInserter or its subclass.
      protected abstract ObjectInserter delegate()  
      void flush()
      Make all inserted objects visible.
      ObjectId idFor​(int type, byte[] data)
      Compute the name of an object, without inserting it.
      ObjectId idFor​(int type, byte[] data, int off, int len)
      Compute the name of an object, without inserting it.
      ObjectId idFor​(int objectType, long length, java.io.InputStream in)
      Compute the name of an object, without inserting it.
      ObjectId idFor​(TreeFormatter formatter)
      Compute the ObjectId for the given tree without inserting it.
      ObjectId insert​(int type, byte[] data)
      Insert a single object into the store, returning its unique name.
      ObjectId insert​(int type, byte[] data, int off, int len)
      Insert a single object into the store, returning its unique name.
      ObjectId insert​(int objectType, long length, 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 release()
      Release any resources used by this inserter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Filter

        public Filter()
    • Method Detail

      • delegate

        protected abstract ObjectInserter delegate()
        Returns:
        delegate ObjectInserter to handle all processing.
      • buffer

        protected byte[] buffer()
        Description copied from class: ObjectInserter
        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.

        Overrides:
        buffer in class ObjectInserter
        Returns:
        a temporary byte array for use by the caller.
      • idFor

        public ObjectId idFor​(int type,
                              byte[] data)
        Description copied from class: ObjectInserter
        Compute the name of an object, without inserting it.
        Overrides:
        idFor in class ObjectInserter
        Parameters:
        type - type code of the object to store.
        data - complete content of the object.
        Returns:
        the name of the object.
      • idFor

        public ObjectId idFor​(int type,
                              byte[] data,
                              int off,
                              int len)
        Description copied from class: ObjectInserter
        Compute the name of an object, without inserting it.
        Overrides:
        idFor 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.
      • idFor

        public ObjectId idFor​(int objectType,
                              long length,
                              java.io.InputStream in)
                       throws java.io.IOException
        Description copied from class: ObjectInserter
        Compute the name of an object, without inserting it.
        Overrides:
        idFor in class ObjectInserter
        Parameters:
        objectType - type code of the object to store.
        length - number of bytes to scan 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 source stream could not be read.
      • insert

        public ObjectId insert​(int type,
                               byte[] data)
                        throws java.io.IOException
        Description copied from class: ObjectInserter
        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.
        Returns:
        the name of the object.
        Throws:
        java.io.IOException - the object could not be stored.
      • insert

        public ObjectId insert​(int type,
                               byte[] data,
                               int off,
                               int len)
                        throws java.io.IOException
        Description copied from class: ObjectInserter
        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 objectType,
                               long length,
                               java.io.InputStream in)
                        throws java.io.IOException
        Description copied from class: ObjectInserter
        Insert a single object into the store, returning its unique name.
        Specified by:
        insert in class ObjectInserter
        Parameters:
        objectType - type code of the object to store.
        length - 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.
      • newPackParser

        public PackParser newPackParser​(java.io.InputStream in)
                                 throws java.io.IOException
        Description copied from class: ObjectInserter
        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()
        Description copied from class: ObjectInserter
        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().

        Specified by:
        newReader in class ObjectInserter
        Returns:
        reader for any object, including an object recently inserted by this inserter since the last flush.
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from class: ObjectInserter
        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.
      • release

        public void release()
        Description copied from class: ObjectInserter
        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:
        release in class ObjectInserter