public class FileBuilder extends AbstractFileSystemItemBuilder<FileBuilder>
Modifier | Constructor and Description |
---|---|
protected |
FileBuilder() |
Modifier and Type | Method and Description |
---|---|
<T> void |
accept(T parentContext,
ResourceCollectionEntryGenerator<T> creator) |
static FileBuilder |
create() |
Map<HashAlgorithm,byte[]> |
getHashAlgorithmToValueMap() |
Long |
getSize() |
String |
getVersion() |
FileBuilder |
hash(HashAlgorithm algorithm,
byte[] hashBytes)
Sets the file's hash value, for the provided algorithm, to the provided value.
|
FileBuilder |
hash(HashAlgorithm algorithm,
File file)
Sets the to-be-built file's hash value, for the provided algorithm, to the provided value.
|
FileBuilder |
hash(HashAlgorithm algorithm,
InputStream is)
Sets the file's hash value, for the provided algorithm, to the provided value.
|
FileBuilder |
hash(HashAlgorithm algorithm,
String hashHexBytes)
Sets the file's hash value, for the provided algorithm, to the provided value.
|
void |
reset() |
FileBuilder |
size(long size)
Sets the to-be-built file's size to the provided value.
|
FileBuilder |
version(String version)
Sets the to-be-built file's version to the provided value.
|
getKey, getLocation, getName, getRoot, location, name, nameAndLocation, root, validate
getLanguage, language
isValid, validateNonEmpty, validateNonEmpty, validateNonEmpty, validateNonEmpty, validateNonNull, validatePatternMatch
public void reset()
reset
in interface Builder
reset
in class AbstractFileSystemItemBuilder<FileBuilder>
public static FileBuilder create()
public <T> void accept(T parentContext, ResourceCollectionEntryGenerator<T> creator)
public Long getSize()
public String getVersion()
public Map<HashAlgorithm,byte[]> getHashAlgorithmToValueMap()
public FileBuilder size(long size)
size
- a non-zero integer indicating the file's size in bytespublic FileBuilder hash(HashAlgorithm algorithm, File file) throws NoSuchAlgorithmException, IOException
InputStream
is used to retrieve the files contents to calculate the hash value. The
caller is resposnible for closing the stream used by this method.algorithm
- the algorithm to establish a hash value forfile
- the file to hashNoSuchAlgorithmException
- if the hash algorithm is not supportedIOException
- if an error occurs while reading the streampublic FileBuilder hash(HashAlgorithm algorithm, InputStream is) throws NoSuchAlgorithmException, IOException
InputStream
is used to retrieve the files contents to calculate the hash value. The
caller is responsible for closing the stream used by this method.algorithm
- the algorithm to establish a hash value foris
- an InputStream
that can be used to read the fileNoSuchAlgorithmException
- if the hash algorithm is not supportedIOException
- if an error occurs while reading the streampublic FileBuilder hash(HashAlgorithm algorithm, byte[] hashBytes)
algorithm
- the algorithm to establish a hash value forhashBytes
- the digest value as a byte array.public FileBuilder hash(HashAlgorithm algorithm, String hashHexBytes)
algorithm
- the algorithm to establish a hash value forhashHexBytes
- the digest value as a hex string.public FileBuilder version(String version)
version
- the version value to useCopyright © 2020 National Institute of Standards and Technology. All rights reserved.