本文整理汇总了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());
}
}
示例2: openStream
import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override public OutputStream openStream() {
return ByteStreams.nullOutputStream();
}