本文整理汇总了Java中com.google.common.io.CountingOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java CountingOutputStream.close方法的具体用法?Java CountingOutputStream.close怎么用?Java CountingOutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CountingOutputStream
的用法示例。
在下文中一共展示了CountingOutputStream.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
private long write(String type, Copier copier) throws IOException {
synchronized (lock) {
if (closed) {
return -1;
}
long startTick = ticker.read();
out.startBlock();
NonClosingCountingOutputStream countingStreamAfterCompression =
new NonClosingCountingOutputStream(out);
CountingOutputStream countingStreamBeforeCompression =
new CountingOutputStream(newLZFOutputStream(countingStreamAfterCompression));
copier.copyTo(countingStreamBeforeCompression);
countingStreamBeforeCompression.close();
long endTick = ticker.read();
CappedDatabaseStats stats = statsByType.get(type);
if (stats == null) {
stats = new CappedDatabaseStats();
statsByType.put(type, stats);
}
stats.record(countingStreamBeforeCompression.getCount(),
countingStreamAfterCompression.getCount(), endTick - startTick);
return out.endBlock();
}
}
示例2: write
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
/**
* @param path root lsm tree index directory
* @param iterator the iterator
* @param keySerializer the key serializer
* @param valueSerializer the value serializer
* @param blocksize block size
* @param keepDeletions true to keep deletion
* @param <K> the key type
* @param <V> the value type
* @throws IOException if an I/O error occurs
*/
public static <K, V> void write(
Path path,
Iterator<Generation.Entry<K,V>> iterator,
Serializer<K> keySerializer,
Serializer<V> valueSerializer,
final int blocksize,
boolean keepDeletions
) throws IOException {
if (blocksize > 65536) throw new IllegalArgumentException("block size must be less than 65536");
Files.createDirectories(path);
final BufferedFileDataOutputStream fileOut = new BufferedFileDataOutputStream(path.resolve("index.bin"));
final CountingOutputStream out = new CountingOutputStream(fileOut);
//tempFile is deleted in writeIndex
final Path tempPath = Files.createTempFile("tmp", ".bin");
final WriteLevelResult result = writeLevel(out, tempPath, iterator, keySerializer, valueSerializer, blocksize, keepDeletions);
final int tmpCount = result.tmpCount;
final long size = result.size;
final long valueLevelLength = out.getCount();
final Header header = writeIndex(out, tempPath, tmpCount, keySerializer, blocksize);
header.valueLevelLength = valueLevelLength;
header.size = size;
header.hasDeletions = keepDeletions;
new HeaderSerializer().write(header, new LittleEndianDataOutputStream(out));
fileOut.sync();
out.close();
}