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

Java HashingOutputStream类代码示例

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

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



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

示例1: serializeOneNestedSet

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
private void serializeOneNestedSet(
    Object children, CodedOutputStream codedOut, Map<Object, byte[]> childToDigest)
    throws IOException, SerializationException {
  // Serialize nested set into an inner byte array so we can take its digest
  ByteArrayOutputStream childOutputStream = new ByteArrayOutputStream();
  HashingOutputStream hashingOutputStream =
      new HashingOutputStream(Hashing.md5(), childOutputStream);
  CodedOutputStream childCodedOut = CodedOutputStream.newInstance(hashingOutputStream);
  if (children instanceof Object[]) {
    serializeMultiItemChildArray((Object[]) children, childToDigest, childCodedOut);
  } else if (children != NestedSet.EMPTY_CHILDREN) {
    serializeSingleItemChildArray(children, childCodedOut);
  } else {
    // Empty set
    childCodedOut.writeInt32NoTag(0);
  }
  childCodedOut.flush();
  byte[] digest = hashingOutputStream.hash().asBytes();
  codedOut.writeByteArrayNoTag(digest);
  byte[] childBytes = childOutputStream.toByteArray();
  codedOut.writeByteArrayNoTag(childBytes);
  childToDigest.put(children, digest);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:24,代码来源:NestedSetCodec.java


示例2: computeHash

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
private static String computeHash(ByteSource source, HashFunction hashFunction)
    throws IOException {
  try (InputStream inputStream = source.openStream();
      HashingOutputStream outputStream =
          new HashingOutputStream(
              hashFunction,
              new OutputStream() {
                @Override
                public void write(int b) throws IOException {
                  // Do nothing.
                }
              })) {
    ByteStreams.copy(inputStream, outputStream);
    return outputStream.hash().toString();
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:17,代码来源:ThriftArtifactCacheProtocol.java


示例3: readPayload

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
public ReadPayloadInfo readPayload(OutputStream outStream) throws IOException {
  assertTrue(
      nextPayloadToBeRead < thriftData.getPayloadsSize(),
      "Trying to download payload index=[%s] but the thriftData only contains [%s] payloads.",
      nextPayloadToBeRead,
      thriftData.getPayloadsSize());

  long payloadSizeBytes =
      assertNotNull(thriftData.getPayloads(), "Payloads[] cannot be null.")
          .get(nextPayloadToBeRead)
          .getSizeBytes();
  try (HashingOutputStream wrappedOutputStream =
      new HashingOutputStream(MD5_HASH_FUNCTION, outStream)) {
    copyExactly(responseStream, wrappedOutputStream, payloadSizeBytes);
    ++nextPayloadToBeRead;
    return new ReadPayloadInfo(payloadSizeBytes, wrappedOutputStream.hash().toString());
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:19,代码来源:ThriftArtifactCacheProtocol.java


示例4: hash

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
/**
 * Encodes the given element using the given coder and hashes the encoding.
 */
static <T> long hash(T element, Coder<T> coder) throws CoderException, IOException {
  try (HashingOutputStream stream =
          new HashingOutputStream(Hashing.murmur3_128(), ByteStreams.nullOutputStream())) {
    coder.encode(element, stream, Context.OUTER);
    return stream.hash().asLong();
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:ApproximateUnique.java


示例5: download

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
public void download(BackupMetadata backup, String filename, OutputStream out) throws IOException {
    if (!(backup.isSuccessful() || backup.isFailed())) {
        throw new IllegalStateException("Attempted to download a non-complete backup.");
    }

    final Timer.Context context = DOWNLOAD_TIMES.time();

    try {
        ACTIVE_DOWNLOADS.inc();

        for (Chunk chunk : backup.getChunks(filename)) {
            final CompressionCodec compressionCodec = chunk.getCompressionCodec();
            final StreamCodec codec = codecFactory.get(compressionCodec, backup.getModelVersion() < 1);

            try (final InputStream in = codec.input(this.openStreamFromStorage(backup.getService(), chunk.getPath()))) {
                final HashingOutputStream md5out = new HashingOutputStream(Hashing.md5(), out);
                final long size = ByteStreams.copy(in, md5out);

                final String hash = md5out.hash().toString();
                if (!hash.equalsIgnoreCase(chunk.getHash())) {
                    throw new InvalidMD5Exception(chunk.getHash(), hash);
                }

                DOWNLOAD_SIZES.update(size);
            }
        }
    }
    catch (IOException e) {
        LOG.error("Failed to download backup: " + backup, e);
        throw e;
    }
    finally {
        ACTIVE_DOWNLOADS.dec();
        context.stop();
    }
}
 
开发者ID:yammer,项目名称:backups,代码行数:37,代码来源:BackupProcessor.java


示例6: data

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
/**
 * Set the input data the given Compression. Will automatically
 * set calculate the md5 sum and length properties
 * @param in InputStream
 * @return Builder
 * @throws IOException
 */
public Builder data(
  InputStream in, 
  Compression<?,?> compression) 
    throws IOException {
  StringWriter writer = new StringWriter();
  OutputStream out = 
    BaseEncoding.base64Url().encodingStream(writer);
  if (compression != null)
    out = compression.compressor(out);
  HashingOutputStream hout = 
    new HashingOutputStream(
      Hashing.md5(), out);
  byte[] buf = new byte[1024];
  int r = -1;
  long size = 0;
  while((r = in.read(buf)) > -1) {
    hout.write(buf,0,r);
    size += r;
  }
  set("length", size);
  if (compression != null) {
    set("compression", compression.label());
    compression.finish(out);
  }
  hout.close();
  set("md5", hout.hash().toString());
  return set("data",writer.toString());
}
 
开发者ID:OpenSocial,项目名称:activitystreams,代码行数:36,代码来源:Binary.java


示例7: writeTo

import com.google.common.hash.HashingOutputStream; //导入依赖的package包/类
public String writeTo(final OutputStream outputStream) throws IOException {
    checkState(appManifest != null || filesetManifest != null,
            "neither AppManifest nor a FilesetManifest is given");

    final OutputStream bufferedOutputStream;
    if (buffering) {
        bufferedOutputStream = new BufferedOutputStream(outputStream);
    } else {
        bufferedOutputStream = outputStream;
    }

    // TODO add encryption capabilities (before or after hashing/compression?) (https://github.com/coreos/rocket/issues/233)

    final OutputStream compressedOutputStream = compression.wrapStream(bufferedOutputStream);

    final HashingOutputStream hashingOutputStream = new HashingOutputStream(Hashing.sha256(),
            compressedOutputStream);

    final TarArchiveOutputStream imageOutputStream = new TarArchiveOutputStream(hashingOutputStream);

    if (appManifest != null) {
        final String appManifestJson = JSON_MAPPER.writeValueAsString(appManifest);

        final TarArchiveEntry appManifestEntry = new TarArchiveEntry("/app");
        appManifestEntry.setSize(appManifestJson.length());

        imageOutputStream.putArchiveEntry(appManifestEntry);
        imageOutputStream.write(appManifestJson.getBytes(MANIFEST_CHARSET));
        imageOutputStream.closeArchiveEntry();
    }

    if (filesetManifest != null) {
        final String filesetManifestJson = JSON_MAPPER.writeValueAsString(filesetManifest);

        final TarArchiveEntry filesetManifestEntry = new TarArchiveEntry("/fileset");
        filesetManifestEntry.setSize(filesetManifestJson.length());

        imageOutputStream.putArchiveEntry(filesetManifestEntry);
        imageOutputStream.write(filesetManifestJson.getBytes(MANIFEST_CHARSET));
        imageOutputStream.closeArchiveEntry();
    }

    for (final Content content : contents) {
        content.addToImage(imageOutputStream);
    }

    imageOutputStream.flush();

    return hashingOutputStream.hash().toString();
}
 
开发者ID:sarnowski,项目名称:aci,代码行数:51,代码来源:ACIWriter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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