• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HashingInputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.common.hash.HashingInputStream的典型用法代码示例。如果您正苦于以下问题:Java HashingInputStream类的具体用法?Java HashingInputStream怎么用?Java HashingInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HashingInputStream类属于com.google.common.hash包,在下文中一共展示了HashingInputStream类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: load

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@SuppressWarnings (
	value = {"resource"}
)
public Model load(InputStream is) throws Exception {
	CountingInputStream countingIs = new CountingInputStream(is);

	HashingInputStream hashingIs = new HashingInputStream(Hashing.md5(), countingIs);

	ModelEvaluator<?> evaluator = unmarshal(hashingIs, this.validate);

	PMML pmml = evaluator.getPMML();

	for(Class<? extends Visitor> visitorClazz : this.visitorClazzes){
		Visitor visitor = visitorClazz.newInstance();

		visitor.applyTo(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;
}
 
开发者ID:openscoring,项目名称:openscoring,代码行数:27,代码来源:ModelRegistry.java


示例2: hash

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
/**
 * hash input with sha256
 *
 * @param is a stream of bytes to hash
 * @return hash result
 */
public static byte[] hash(InputStream is) {
    HashingInputStream his = new HashingInputStream(Hashing.sha256(), is);
    try {
        ByteStreams.copy(his, ByteStreams.nullOutputStream());
        return his.hash().asBytes();
    } catch (IOException e) {
        throw new RuntimeException("Unable to compute hash while signing request: " + e.getMessage(), e);
    }
}
 
开发者ID:esiqveland,项目名称:okhttp-awssigner,代码行数:16,代码来源:JCloudTools.java


示例3: hash

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
/**
 * Computes the hash of the given stream using the given algorithm.
 */
public static HashCode hash(final HashAlgorithm algorithm, final InputStream inputStream) throws IOException {
  checkNotNull(algorithm);
  checkNotNull(inputStream);

  try (HashingInputStream hashingStream = new HashingInputStream(algorithm.function(), inputStream)) {
    ByteStreams.copy(hashingStream, ByteStreams.nullOutputStream());
    return hashingStream.hash();
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:13,代码来源:Hashes.java


示例4: interrogate

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@Override public String interrogate(InputStream rawInputStream,
                          Optional<List<ZipMiningHandler.Entry>> handlers) throws IOException {
    final HashingInputStream hashingInputStream = new HashingInputStream(fileIdHash, rawInputStream);

    final ZipInputStream zipInputStream = new ZipInputStream(hashingInputStream);

    ZipEntry zipEntry;
    while ((zipEntry = zipInputStream.getNextEntry()) != null) {
        if (handlers != null) {
            final String name = zipEntry.getName();
            handlers.orElse(Collections.emptyList()).stream()
                    .filter(e -> e.getPath().matcher(name).matches())
                    .forEach(e -> {
                        final ZipMiningHandler handler = e.getHandler();
                        try {
                            handler.handleZipContentFile(name, StreamUtils.nonClosing(zipInputStream));
                        } catch (IOException | MccyException e1) {
                            LOG.warn("Handler {} failed to process zip content file named {}", handler, e1);
                        }
                    });
        }
    }

    // Need to read off the remaining content of the zip file to generate the full hash
    final byte[] buffer = new byte[1024];
    //noinspection StatementWithEmptyBody
    while (hashingInputStream.read(buffer) != -1){}

    return hashingInputStream.hash().toString();
}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:31,代码来源:ZipMiningServiceImpl.java


示例5: testRawHashOfFile

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@Test
public void testRawHashOfFile() throws Exception {
    final ClassPathResource worldResource = new ClassPathResource("NewWorld.zip");
    try (InputStream in = worldResource.getInputStream()) {
        final HashingInputStream hashingInputStream = new HashingInputStream(Hashing.md5(), in);
        final byte[] buffer = new byte[1024];
        while (hashingInputStream.read(buffer) != -1){}

        assertEquals("2a9eaf43128d05bbebbb9a0d4b9f8892", hashingInputStream.hash().toString());
    }

}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:13,代码来源:ZipMiningServiceTest.java


示例6: copy

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
private static String copy(ProtocolHandler sourceProtocolHandler, ProtocolHandler destinationProtocolHandler, long contentLength)
        throws IOException, NoSuchAlgorithmException {

    try (InputStream inputStream = sourceProtocolHandler.openStream(); HashingInputStream hashingInputStream = new HashingInputStream(Hashing.md5(), inputStream);
            CountingInputStream countingInputStream = new CountingInputStream(hashingInputStream)) {
        destinationProtocolHandler.copyTo(countingInputStream, contentLength);
        return hashingInputStream.hash().toString();
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:10,代码来源:ManifestTool.java


示例7: process

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@Nonnull
public String process(@Nonnull InputStream in) throws IOException {
	checkNotNull(in);
	try {
		HashingInputStream hashIn = new HashingInputStream(function, in);
		IOUtils.copy(hashIn, ByteStreams.nullOutputStream());
		return encoding.encode(hashIn.hash().asBytes());
	} finally {
		IOUtils.closeQuietly(in);
	}
}
 
开发者ID:lithiumtech,项目名称:flow,代码行数:12,代码来源:HashEncoder.java


示例8: storeChunk

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
private long storeChunk(BackupMetadata backup, InputStream in, final String path, final String filename, final CompressionCodec compressionCodec) throws IOException {
    final CountingOutputStream countingOut = new CountingOutputStream(localStorage.upload(backup.getService(), path));

    final StreamCodec codec = codecFactory.get(compressionCodec, backup.getModelVersion() < 1);

    try (final OutputStream out = codec.output(countingOut)) {
        final HashingInputStream md5in = new HashingInputStream(Hashing.md5(), in);

        LOG.debug("Storing {} chunk {} locally", backup, path);

        final long originalSize = ByteStreams.copy(md5in, out);
        if (originalSize > 0) {
            final long size = countingOut.getCount();
            final String hash = md5in.hash().toString();

            this.update(backup, new Function<BackupMetadata, BackupMetadata>() {
                @Override
                public BackupMetadata apply(BackupMetadata input) {
                    input.addChunk(filename, path, originalSize, size, hash, getNodeName(), compressionCodec);
                    return input;
                }
            });

            LOG.debug("Stored {} chunk {} (originalSize: {}, size: {}) locally", backup, path, originalSize, size);

            // Upload this chunk offsite in another thread
            this.uploadChunk(backup, path);
        }

        return originalSize;
    }
}
 
开发者ID:yammer,项目名称:backups,代码行数:33,代码来源:BackupProcessor.java


示例9: fetchResource

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
private void fetchResource(String name, File target) throws IOException {
    try (final HashingInputStream in = new HashingInputStream(HASH_FUNCTION, fetchResource(name))) {
        Files.asByteSink(target).writeFrom(in);

        LOG.debug("Downloaded {} (hash: {})", name, in.hash());
    }
}
 
开发者ID:reines,项目名称:rsc,代码行数:8,代码来源:ResourceStore.java


示例10: manifestContainsEntryHashesOfHashedEntries

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@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();

    String expectedHash = hashingContents.hash().toString();
    assertEntryHash(entryName, expectedHash);
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:14,代码来源:CustomJarOutputStreamTest.java


示例11: manifestContainsEntryHashesOfEmptyHashedEntries

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@Test
public void manifestContainsEntryHashesOfEmptyHashedEntries() throws IOException {
  String entryName = "A";
  InputStream contents = new ByteArrayInputStream(new byte[0]);
  try (HashingInputStream hashingContents =
      new HashingInputStream(Hashing.murmur3_128(), contents)) {
    writer.putNextEntry(new CustomZipEntry(entryName));
    writer.closeEntry();
    writer.close();

    String expectedHash = hashingContents.hash().toString();
    assertEntryHash(entryName, expectedHash);
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:15,代码来源:CustomJarOutputStreamTest.java


示例12: testInterceptFiles

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
@Test
public void testInterceptFiles() throws Exception {
    final ClassPathResource worldResource = new ClassPathResource("NewWorld.zip");
    final String id;
    CompletableFuture<String> hashOfLevelDat = new CompletableFuture<>();

    final String[] expectedDataDatFiles = new String[]{
            "Mineshaft.dat",
            "Temple.dat",
            "villages.dat",
            "villages_end.dat",
            "villages_nether.dat"
    };

    AtomicInteger dataDatCount = new AtomicInteger();

    try (InputStream worldIn = worldResource.getInputStream()) {

        id = service.interrogate(worldIn, ZipMiningHandler.listBuilder()
                .add(".*/level.dat", ((path, in) -> {
                    final HashingInputStream hashLevelDatIn = new HashingInputStream(Hashing.md5(), in);
                    byte[] buffer = new byte[1024];
                    try {
                        while (hashLevelDatIn.read(buffer) != -1){}
                        hashOfLevelDat.complete(hashLevelDatIn.hash().toString());
                    } catch (IOException e) {
                        hashOfLevelDat.completeExceptionally(e);
                    }
                }))
                .add(".*/data/.*\\.dat", (path, in) -> {

                    final int pos = path.lastIndexOf("/");
                    assertThat(path.substring(pos + 1), Matchers.isIn(expectedDataDatFiles));

                    dataDatCount.incrementAndGet();
                })
                .build());

        assertTrue(hashOfLevelDat.isDone());
        assertEquals("7661c3e52e999aeb6b5593072d189be0", hashOfLevelDat.get());

        assertEquals(5L, dataDatCount.longValue());
    }
    assertEquals("2a9eaf43128d05bbebbb9a0d4b9f8892", id);
}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:46,代码来源:ZipMiningServiceTest.java


示例13: store

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
public void store(BackupMetadata backup, Optional<String> contentMD5, InputStream in, String filename) throws IOException {
    final Timer.Context context = STORE_TIMES.time();

    try {
        ACTIVE_STORES.inc();
        incrementPendingStores(backup, filename);

        // If the file is already compressed then don't bother compressing it again
        final boolean originallyCompressed = isCompressed(filename);
        final CompressionCodec compressionCodec = originallyCompressed ? CompressionCodec.NONE : codecFactory.getDefaultCompressionCodec();

        LOG.trace("Compressing {} file {} using {}", backup, filename, compressionCodec);

        try (final HashingInputStream md5in = new HashingInputStream(Hashing.md5(), in)) {
            // Store all chunks
            final long size = this.storeChunks(backup, md5in, filename, compressionCodec);
            if (size == 0) {
                throw new NoContentException(String.format("No content received for %s (service: %s, id: %s)", filename, backup.getService(), backup.getId()));
            }

            STORE_SIZES.update(size);

            final String calculatedMD5 = md5in.hash().toString();
            if (contentMD5.isPresent() && !calculatedMD5.equalsIgnoreCase(contentMD5.get())) {
                throw new InvalidMD5Exception(contentMD5.get(), calculatedMD5);
            }
        }

        decrementPendingStores(backup, filename);
        fireBackupUploaded(backup, filename);
    }
    catch (final Exception e) {
        this.update(backup, new Function<BackupMetadata, BackupMetadata>() {
            @Override
            public BackupMetadata apply(BackupMetadata input) {
                LOG.error("Failed to store backup: " + input, e);
                input.setFailed("Failed to store backup: " + e.getMessage());
                return input;
            }
        });

        throw e;
    }
    finally {
        ACTIVE_STORES.dec();
        context.stop();
    }
}
 
开发者ID:yammer,项目名称:backups,代码行数:49,代码来源:BackupProcessor.java


示例14: dumpBinaryFile

import com.google.common.hash.HashingInputStream; //导入依赖的package包/类
private Stream<String> dumpBinaryFile(String name, InputStream inputStream) throws IOException {
  try (HashingInputStream is = new HashingInputStream(Hashing.murmur3_128(), inputStream)) {
    ByteStreams.exhaust(is);
    return Stream.of(String.format("Murmur3-128 of %s: %s", name, is.hash().toString()));
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:7,代码来源:JarDumper.java



注:本文中的com.google.common.hash.HashingInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ServiceDefinition类代码示例发布时间:2022-05-22
下一篇:
Java JWTCreationException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap