当前位置: 首页>>代码示例>>Java>>正文


Java ByteStreams.nullOutputStream方法代码示例

本文整理汇总了Java中com.google.common.io.ByteStreams.nullOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ByteStreams.nullOutputStream方法的具体用法?Java ByteStreams.nullOutputStream怎么用?Java ByteStreams.nullOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.ByteStreams的用法示例。


在下文中一共展示了ByteStreams.nullOutputStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWriteLayer

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Test
public void testWriteLayer() throws URISyntaxException, IOException {
  Path blobA = Paths.get(Resources.getResource("blobA").toURI());
  String expectedBlobAString = new String(Files.readAllBytes(blobA), StandardCharsets.UTF_8);

  // Gets the expected content descriptor and diff ID.
  CountingDigestOutputStream compressedDigestOutputStream =
      new CountingDigestOutputStream(ByteStreams.nullOutputStream());
  CountingDigestOutputStream uncompressedDigestOutputStream;
  try (GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream)) {
    uncompressedDigestOutputStream = new CountingDigestOutputStream(compressorStream);
    byte[] expectedBlobABytes = expectedBlobAString.getBytes(StandardCharsets.UTF_8);
    uncompressedDigestOutputStream.write(expectedBlobABytes);
  }

  BlobDescriptor expectedBlobADescriptor = compressedDigestOutputStream.toBlobDescriptor();
  DescriptorDigest expectedBlobADiffId =
      uncompressedDigestOutputStream.toBlobDescriptor().getDigest();

  // Writes blobA as a layer to the cache.
  CacheWriter cacheWriter = new CacheWriter(testCache);

  UnwrittenLayer unwrittenLayer = new UnwrittenLayer(Blobs.from(blobA));

  CachedLayer cachedLayer = cacheWriter.writeLayer(unwrittenLayer);

  // Reads the cached layer back.
  Path compressedBlobFile = cachedLayer.getContentFile();

  try (InputStreamReader fileReader =
      new InputStreamReader(
          new GZIPInputStream(Files.newInputStream(compressedBlobFile)),
          StandardCharsets.UTF_8)) {
    String decompressedString = CharStreams.toString(fileReader);

    Assert.assertEquals(expectedBlobAString, decompressedString);
    Assert.assertEquals(
        expectedBlobADescriptor.getSize(), cachedLayer.getBlobDescriptor().getSize());
    Assert.assertEquals(
        expectedBlobADescriptor.getDigest(), cachedLayer.getBlobDescriptor().getDigest());
    Assert.assertEquals(expectedBlobADescriptor, cachedLayer.getBlobDescriptor());
    Assert.assertEquals(expectedBlobADiffId, cachedLayer.getDiffId());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:45,代码来源:CacheWriterTest.java

示例2: openStream

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override public OutputStream openStream() {
  return ByteStreams.nullOutputStream();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:ArbitraryInstances.java


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