Package org.apache.commons.codec.digest
Class GitIdentifiers.TreeIdBuilder
java.lang.Object
org.apache.commons.codec.digest.GitIdentifiers.TreeIdBuilder
- All Implemented Interfaces:
Supplier<byte[]>
- Enclosing class:
GitIdentifiers
Builds a Git tree identifier for a virtual directory structure, such as the contents of
an archive.
-
Method Summary
Modifier and TypeMethodDescriptionaddDirectory(String name) Adds and returns theGitIdentifiers.TreeIdBuilderfor the named subdirectory, creating it if absent.voidaddFile(GitIdentifiers.FileMode mode, String name, byte[] data) Adds a file entry at the given path within this tree.voidaddFile(GitIdentifiers.FileMode mode, String name, long dataSize, InputStream data) Adds a file entry at the given path within this tree, streaming content without buffering.voidaddSymbolicLink(String name, String target) Adds a symbolic link entry at the given path within this tree.byte[]get()Computes the Git tree identifier for this directory and all its descendants.
-
Method Details
-
addDirectory
Adds and returns theGitIdentifiers.TreeIdBuilderfor the named subdirectory, creating it if absent.- Parameters:
name- The relative path of the subdirectory in normalized form (may contain'/').- Returns:
- The
GitIdentifiers.TreeIdBuilderfor the subdirectory. - Throws:
IllegalArgumentException- If any path component is"..".
-
addFile
Adds a file entry at the given path within this tree.If
namecontains'/', 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- If an I/O error occurs.IllegalArgumentException- If any path component is"..".
-
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
namecontains'/', 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 indata.data- The file content.- Throws:
IOException- If the stream cannot be read.IllegalArgumentException- If any path component is"..".
-
addSymbolicLink
Adds a symbolic link entry at the given path within this tree.If
namecontains'/', 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- If an I/O error occurs.IllegalArgumentException- If any path component is"..".
-
get
Computes the Git tree identifier for this directory and all its descendants.
-