Class GitIdentifiers.TreeIdBuilder

java.lang.Object
org.apache.commons.codec.digest.GitIdentifiers.TreeIdBuilder
All Implemented Interfaces:
Supplier<byte[]>
Enclosing class:
GitIdentifiers

public static final class GitIdentifiers.TreeIdBuilder extends Object implements Supplier<byte[]>
Builds a Git tree identifier for a virtual directory structure, such as the contents of an archive.
Since:
1.22.0
  • Method Details

    • addDirectory

      Adds and returns the GitIdentifiers.TreeIdBuilder for the named subdirectory, creating it if absent.
      Parameters:
      name - The relative path of the subdirectory in normalized form (may contain '/').
      Returns:
      The GitIdentifiers.TreeIdBuilder for the subdirectory.
      Throws:
      IllegalArgumentException - Thrown if any path component is "..", contains NUL or contains unpaired surrogates.
    • addFile

      public void addFile(GitIdentifiers.FileMode mode, String name, byte[] data) throws IOException
      Adds a file entry at the given path within this tree.

      If name contains '/', intermediate subdirectories are created automatically.

      Parameters:
      mode - The file mode (e.g. GitIdentifiers.FileMode.REGULAR).
      name - The relative path of the entry in normalized form(may contain '/').
      data - The file content.
      Throws:
      IOException - Thrown if an I/O error occurs.
      IllegalArgumentException - Thrown if the entry name is empty or ".", or any path component is "..", contains NUL or contains unpaired surrogates.
    • addFile

      public void addFile(GitIdentifiers.FileMode mode, String name, long dataSize, InputStream data) throws IOException
      Adds a file entry at the given path within this tree, streaming content without buffering.

      If name contains '/', intermediate subdirectories are created automatically.

      The stream is eagerly drained.

      Parameters:
      mode - The file mode (e.g. GitIdentifiers.FileMode.REGULAR).
      name - The relative path of the entry in normalized form(may contain '/').
      dataSize - The exact number of bytes in data.
      data - The file content.
      Throws:
      IOException - Thrown if the stream cannot be read, or does not contain exactly dataSize bytes.
      IllegalArgumentException - Thrown if the entry name is empty or ".", or any path component is "..", contains NUL or contains unpaired surrogates.
    • addSymbolicLink

      public void addSymbolicLink(String name, String target) throws IOException
      Adds a symbolic link entry at the given path within this tree.

      If name contains '/', intermediate subdirectories are created automatically.

      Parameters:
      name - The relative path of the entry in normalized form(may contain '/').
      target - The target of the symbolic link.
      Throws:
      IOException - Thrown if an I/O error occurs.
      IllegalArgumentException - Thrown if the entry name is empty or ".", or any path component is "..", contains NUL or contains unpaired surrogates.
    • get

      public byte[] get()
      Gets the Git tree identifier for this directory and all its descendants.
      Specified by:
      get in interface Supplier<byte[]>
      Returns:
      The raw tree identifier bytes.
      Throws:
      IllegalStateException - Thrown if a file and a directory have the same name in this directory or any descendant.