use of com.google.common.hash.HashingInputStream in project buck by facebook.
the class HashingDeterministicJarWriter method writeEntry.
public HashingDeterministicJarWriter writeEntry(String name, InputStream contents) throws IOException {
try (HashingInputStream hashingContents = new HashingInputStream(Hashing.murmur3_128(), contents)) {
writeToJar(name, hashingContents);
manifestWriter.setEntryAttribute(name, DIGEST_ATTRIBUTE_NAME, hashingContents.hash().toString());
}
return this;
}
use of com.google.common.hash.HashingInputStream in project openscoring by openscoring.
the class ModelRegistry method load.
@SuppressWarnings(value = { "resource" })
public Model load(InputStream is) throws Exception {
CountingInputStream countingIs = new CountingInputStream(is);
HashingInputStream hashingIs = new HashingInputStream(Hashing.md5(), countingIs);
PMML pmml = unmarshal(hashingIs, this.validate);
this.visitorBattery.applyTo(pmml);
ModelEvaluatorFactory modelEvaluatorFactory = this.modelEvaluatorFactory;
Evaluator evaluator = modelEvaluatorFactory.newModelEvaluator(pmml);
evaluator.verify();
Model model = new Model(evaluator);
model.putProperty(Model.PROPERTY_FILE_SIZE, countingIs.getCount());
model.putProperty(Model.PROPERTY_FILE_MD5SUM, (hashingIs.hash()).toString());
return model;
}
use of com.google.common.hash.HashingInputStream in project buck by facebook.
the class HashingDeterministicJarWriterTest method manifestContainsEntryHashesOfHashedEntries.
@Test
public void manifestContainsEntryHashesOfHashedEntries() throws IOException {
String entryName = "A";
InputStream contents = new ByteArrayInputStream("contents".getBytes(StandardCharsets.UTF_8));
try (HashingInputStream hashingContents = new HashingInputStream(Hashing.murmur3_128(), contents)) {
writer.writeEntry(entryName, hashingContents);
writer.close();
try (JarInputStream jar = new JarInputStream(new ByteArrayInputStream(out.toByteArray()))) {
jar.getNextJarEntry();
JarEntry manifestEntry = jar.getNextJarEntry();
assertEquals(JarFile.MANIFEST_NAME, manifestEntry.getName());
Manifest manifest = new Manifest();
manifest.read(jar);
String expectedHash = hashingContents.hash().toString();
assertEquals(expectedHash, manifest.getEntries().get(entryName).getValue("Murmur3-128-Digest"));
}
}
}
use of com.google.common.hash.HashingInputStream in project atlas by alibaba.
the class AtlasDesugarTransform method initDesugarJar.
/**
* Set this location of extracted desugar jar that is used for processing.
*/
private static void initDesugarJar(@Nullable FileCache cache) throws IOException {
if (isDesugarJarInitialized()) {
return;
}
URL url = DesugarProcessBuilder.class.getClassLoader().getResource(DESUGAR_JAR);
Preconditions.checkNotNull(url);
Path extractedDesugar = null;
if (cache != null) {
try {
String fileHash;
try (HashingInputStream stream = new HashingInputStream(Hashing.sha256(), url.openStream())) {
fileHash = stream.hash().toString();
}
FileCache.Inputs inputs = new FileCache.Inputs.Builder(FileCache.Command.EXTRACT_DESUGAR_JAR).putString("pluginVersion", Version.ANDROID_GRADLE_PLUGIN_VERSION).putString("jarUrl", url.toString()).putString("fileHash", fileHash).build();
File cachedFile = cache.createFileInCacheIfAbsent(inputs, file -> copyDesugarJar(url, file.toPath())).getCachedFile();
Preconditions.checkNotNull(cachedFile);
extractedDesugar = cachedFile.toPath();
} catch (IOException | ExecutionException e) {
logger.error(e, "Unable to cache Desugar jar. Extracting to temp dir.");
}
}
synchronized (desugarJar) {
if (isDesugarJarInitialized()) {
return;
}
if (extractedDesugar == null) {
extractedDesugar = PathUtils.createTmpToRemoveOnShutdown(DESUGAR_JAR);
copyDesugarJar(url, extractedDesugar);
}
desugarJar.set(extractedDesugar);
}
}
Aggregations