use of org.gradle.internal.hash.HashValue in project gradle by gradle.
the class ExternalResourceResolver method createChecksumFile.
private byte[] createChecksumFile(File src, String algorithm, int checksumLength) {
HashValue hash = HashUtil.createHash(src, algorithm);
String formattedHashString = hash.asZeroPaddedHexString(checksumLength);
try {
return formattedHashString.getBytes("US-ASCII");
} catch (UnsupportedEncodingException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of org.gradle.internal.hash.HashValue in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method copyCandidateToCache.
private LocallyAvailableExternalResource copyCandidateToCache(URI source, ResourceFileStore fileStore, ExternalResourceMetaData remoteMetaData, HashValue remoteChecksum, LocallyAvailableResource local) throws IOException {
final File destination = temporaryFileProvider.createTemporaryFile("gradle_download", "bin");
try {
Files.copy(local.getFile(), destination);
HashValue localChecksum = HashUtil.createHash(destination, "SHA1");
if (!localChecksum.equals(remoteChecksum)) {
return null;
}
return moveIntoCache(source, destination, fileStore, remoteMetaData);
} finally {
destination.delete();
}
}
use of org.gradle.internal.hash.HashValue in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.
private HashValue getResourceSha1(URI location, boolean revalidate) {
try {
URI sha1Location = new URI(location.toASCIIString() + ".sha1");
ExternalResource resource = delegate.getResource(sha1Location, revalidate);
if (resource == null) {
return null;
}
try {
return resource.withContent(new Transformer<HashValue, InputStream>() {
@Override
public HashValue transform(InputStream inputStream) {
try {
String sha = IOUtils.toString(inputStream, "us-ascii");
return HashValue.parse(sha);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
} finally {
resource.close();
}
} catch (Exception e) {
throw new ResourceException(location, String.format("Failed to download SHA1 for resource '%s'.", location), e);
}
}
Aggregations