Package org.apache.commons.codec.digest
Class GitIdentifiers.TreeIdBuilder
- java.lang.Object
-
- org.apache.commons.codec.digest.GitIdentifiers.TreeIdBuilder
-
- All Implemented Interfaces:
java.util.function.Supplier<byte[]>
- Enclosing class:
- GitIdentifiers
public static final class GitIdentifiers.TreeIdBuilder extends java.lang.Object implements java.util.function.Supplier<byte[]>Builds a Git tree identifier for a virtual directory structure, such as the contents of an archive.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceGitIdentifiers.TreeIdBuilder.BlobIdSupplierSupplies a blob identifier that may throwIOException.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,GitIdentifiers.TreeIdBuilder>dirEntriesprivate java.util.Map<java.lang.String,GitIdentifiers.DirectoryEntry>fileEntriesprivate java.security.MessageDigestmessageDigest
-
Constructor Summary
Constructors Modifier Constructor Description privateTreeIdBuilder(java.security.MessageDigest messageDigest)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GitIdentifiers.TreeIdBuilderaddDirectory(java.lang.String name)Adds and returns theGitIdentifiers.TreeIdBuilderfor the named subdirectory, creating it if absent.voidaddFile(GitIdentifiers.FileMode mode, java.lang.String name, byte[] data)Adds a file entry at the given path within this tree.voidaddFile(GitIdentifiers.FileMode mode, java.lang.String name, long dataSize, java.io.InputStream data)Adds a file entry at the given path within this tree, streaming content without buffering.private voidaddFile(GitIdentifiers.FileMode mode, java.lang.String name, GitIdentifiers.TreeIdBuilder.BlobIdSupplier blobId)voidaddSymbolicLink(java.lang.String name, java.lang.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.private GitIdentifiers.TreeIdBuilderpopulate(java.nio.file.Path directory)private static java.lang.StringrequireNoParentTraversal(java.lang.String name)
-
-
-
Field Detail
-
dirEntries
private final java.util.Map<java.lang.String,GitIdentifiers.TreeIdBuilder> dirEntries
-
fileEntries
private final java.util.Map<java.lang.String,GitIdentifiers.DirectoryEntry> fileEntries
-
messageDigest
private final java.security.MessageDigest messageDigest
-
-
Method Detail
-
requireNoParentTraversal
private static java.lang.String requireNoParentTraversal(java.lang.String name)
-
addDirectory
public GitIdentifiers.TreeIdBuilder addDirectory(java.lang.String name)
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:
java.lang.IllegalArgumentException- If any path component is"..".
-
addFile
private void addFile(GitIdentifiers.FileMode mode, java.lang.String name, GitIdentifiers.TreeIdBuilder.BlobIdSupplier blobId) throws java.io.IOException
- Throws:
java.io.IOException
-
addFile
public void addFile(GitIdentifiers.FileMode mode, java.lang.String name, byte[] data) throws java.io.IOException
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:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If any path component is"..".
-
addFile
public void addFile(GitIdentifiers.FileMode mode, java.lang.String name, long dataSize, java.io.InputStream data) throws java.io.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:
java.io.IOException- If the stream cannot be read.java.lang.IllegalArgumentException- If any path component is"..".
-
addSymbolicLink
public void addSymbolicLink(java.lang.String name, java.lang.String target) throws java.io.IOExceptionAdds 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:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If any path component is"..".
-
get
public byte[] get()
Computes the Git tree identifier for this directory and all its descendants.- Specified by:
getin interfacejava.util.function.Supplier<byte[]>- Returns:
- The raw tree identifier bytes.
-
populate
private GitIdentifiers.TreeIdBuilder populate(java.nio.file.Path directory) throws java.io.IOException
- Throws:
java.io.IOException
-
-