Class DirCacheEditor


  • public class DirCacheEditor
    extends BaseDirCacheEditor
    Updates a DirCache by supplying discrete edit commands.

    An editor updates a DirCache by taking a list of DirCacheEditor.PathEdit commands and executing them against the entries of the destination cache to produce a new cache. This edit style allows applications to insert a few commands and then have the editor compute the proper entry indexes necessary to perform an efficient in-order update of the index records. This can be easier to use than DirCacheBuilder.

    See Also:
    DirCacheBuilder
    • Constructor Detail

      • DirCacheEditor

        protected DirCacheEditor​(DirCache dc,
                                 int ecnt)
        Construct a new editor.
        Parameters:
        dc - the cache this editor will eventually update.
        ecnt - estimated number of entries the editor will have upon completion. This sizes the initial entry table.
    • Method Detail

      • add

        public void add​(DirCacheEditor.PathEdit edit)
        Append one edit command to the list of commands to be applied.

        Edit commands may be added in any order chosen by the application. They are automatically rearranged by the builder to provide the most efficient update possible.

        Parameters:
        edit - another edit command.
      • commit

        public boolean commit()
                       throws java.io.IOException
        Finish, write, commit this change, and release the index lock.

        If this method fails (returns false) the lock is still released.

        This is a utility method for applications as the finish-write-commit pattern is very common after using a builder to update entries.

        Overrides:
        commit in class BaseDirCacheEditor
        Returns:
        true if the commit was successful and the file contains the new data; false if the commit failed and the file remains with the old data.
        Throws:
        java.io.IOException - the output file could not be created. The caller no longer holds the lock.
      • applyEdits

        private void applyEdits()
      • deleteOverlappingSubtree

        private int deleteOverlappingSubtree​(DirCacheEntry ent,
                                             int eIdx)
      • findEntry

        private int findEntry​(byte[] p,
                              int pLen)
      • inDir

        private static boolean inDir​(DirCacheEntry e,
                                     byte[] path,
                                     int pLen)
      • pdir

        private static int pdir​(byte[] path,
                                int e)