本文整理汇总了Java中com.google.common.io.CountingOutputStream.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java CountingOutputStream.getCount方法的具体用法?Java CountingOutputStream.getCount怎么用?Java CountingOutputStream.getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CountingOutputStream
的用法示例。
在下文中一共展示了CountingOutputStream.getCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmptyWorks
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
MessageCodec cmc = new MessageCodec();
Codec.Encoder encoder = cmc.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = cmc.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
示例2: testOne
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
MessageCodec cmc = new MessageCodec();
Codec.Encoder encoder = cmc.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = cmc.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
assertFalse(decoder.advance()); // Second read should trip over the end-of-stream marker and return false
dis.close();
assertEquals(offset, cis.getCount());
}
示例3: testEmptyWorks
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
KeyValueCodec kvc = new KeyValueCodec();
Codec.Encoder encoder = kvc.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = kvc.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
示例4: testOne
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
KeyValueCodec kvc = new KeyValueCodec();
Codec.Encoder encoder = kvc.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
final long length = kv.getLength() + Bytes.SIZEOF_INT;
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(length, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = kvc.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
// Second read should trip over the end-of-stream marker and return false
assertFalse(decoder.advance());
dis.close();
assertEquals(length, cis.getCount());
}
示例5: testEmptyWorks
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
示例6: testOne
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
kv.setSequenceId(Long.MAX_VALUE);
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
// Second read should trip over the end-of-stream marker and return false
assertFalse(decoder.advance());
dis.close();
assertEquals(offset, cis.getCount());
}
示例7: byteCount
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
/**
* Calculate the serialized object size in bytes. This is a good indication of how much memory the object roughly takes.
* Note that this is typically not exactly the same for many objects.
* @param object any object that implements {@link Serializable}
* @return number of bytes of the serialized object.
*/
public long byteCount(Object object) {
try {
CountingOutputStream cos = new CountingOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
// do nothing
}
});
ObjectOutputStream os = new ObjectOutputStream(cos);
os.writeObject(object);
os.flush();
os.close();
return cos.getCount();
} catch (IOException e) {
throw new IllegalStateException("error serializing object: " + e.getMessage(),e);
}
}
示例8: testOne
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
kv.setMvccVersion(Long.MAX_VALUE);
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
// Second read should trip over the end-of-stream marker and return false
assertFalse(decoder.advance());
dis.close();
assertEquals(offset, cis.getCount());
}
示例9: testOne
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
// Second read should trip over the end-of-stream marker and return false
assertFalse(decoder.advance());
dis.close();
assertEquals(offset, cis.getCount());
}
示例10: writeRecords
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public static int[] writeRecords(final String path, final int numRecords, final WarcRecord[] randomRecords, final int parallel) throws IOException, InterruptedException {
final ProgressLogger pl = new ProgressLogger(LOGGER, "records");
if (parallel <= 1) pl.expectedUpdates = numRecords;
final ProgressLogger plb = new ProgressLogger(LOGGER, "KB");
final CountingOutputStream cos = new CountingOutputStream(new FastBufferedOutputStream(new FileOutputStream (path)));
final WarcWriter ww;
if (parallel == 0) {
ww = new UncompressedWarcWriter(cos);
pl.start("Writing records…");
} else if (parallel == 1) {
ww = new CompressedWarcWriter(cos);
pl.start("Writing records (compressed)…");
} else {
ww = null;
pl.start("SHOULD NOT HAPPEN");
throw new IllegalStateException();
}
plb.start();
long written = 0;
final int[] position = new int[numRecords];
for (int i = 0; i < numRecords; i++) {
final int pos = RandomTestMocks.RNG.nextInt(randomRecords.length);
position[i] = pos;
ww.write(randomRecords[pos]);
if (parallel <= 0) {
pl.lightUpdate();
plb.update((cos.getCount() - written) / 1024);
}
written = cos.getCount();
}
ww.close();
pl.done(numRecords);
plb.done(cos.getCount());
return position;
}
示例11: testThree
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testThree() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
MessageCodec cmc = new MessageCodec();
Codec.Encoder encoder = cmc.getEncoder(dos);
final KeyValue kv1 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
final KeyValue kv2 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
final KeyValue kv3 = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
encoder.write(kv1);
encoder.write(kv2);
encoder.write(kv3);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = cmc.getDecoder(dis);
assertTrue(decoder.advance());
Cell c = decoder.current();
assertTrue(CellComparator.equals(c, kv1));
assertTrue(decoder.advance());
c = decoder.current();
assertTrue(CellComparator.equals(c, kv2));
assertTrue(decoder.advance());
c = decoder.current();
assertTrue(CellComparator.equals(c, kv3));
assertFalse(decoder.advance());
dis.close();
assertEquals(offset, cis.getCount());
}
示例12: testThree
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testThree() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
final KeyValue kv1 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
final KeyValue kv2 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
final KeyValue kv3 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
encoder.write(kv1);
encoder.write(kv2);
encoder.write(kv3);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertTrue(decoder.advance());
Cell c = decoder.current();
assertTrue(CellComparator.equals(c, kv1));
assertTrue(decoder.advance());
c = decoder.current();
assertTrue(CellComparator.equals(c, kv2));
assertTrue(decoder.advance());
c = decoder.current();
assertTrue(CellComparator.equals(c, kv3));
assertFalse(decoder.advance());
dis.close();
assertEquals(offset, cis.getCount());
}
示例13: compressStreamWithGZIPNoDigest
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
/**
* Compress an input stream with GZIP and return the result size, digest and
* compressed stream.
*
* @param inputStream
* @return the compressed stream
* @throws SnowflakeSQLException
* @deprecated Can be removed when all accounts are encrypted
*/
private static InputStreamWithMetadata compressStreamWithGZIPNoDigest(
InputStream inputStream) throws SnowflakeSQLException
{
try
{
FileBackedOutputStream tempStream =
new FileBackedOutputStream(MAX_BUFFER_SIZE, true);
CountingOutputStream countingStream =
new CountingOutputStream(tempStream);
// construct a gzip stream with sync_flush mode
GZIPOutputStream gzipStream;
gzipStream = new GZIPOutputStream(countingStream, true);
IOUtils.copy(inputStream, gzipStream);
inputStream.close();
gzipStream.finish();
gzipStream.flush();
countingStream.flush();
return new InputStreamWithMetadata(countingStream.getCount(),
null, tempStream);
}
catch (IOException ex)
{
logger.error("Exception compressing input stream", ex);
throw new SnowflakeSQLException(ex, SqlState.INTERNAL_ERROR,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
"error encountered for compression");
}
}
示例14: testThree
import com.google.common.io.CountingOutputStream; //导入方法依赖的package包/类
@Test
public void testThree() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
KeyValueCodec kvc = new KeyValueCodec();
Codec.Encoder encoder = kvc.getEncoder(dos);
final KeyValue kv1 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("1"));
final KeyValue kv2 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("2"), Bytes.toBytes("2"));
final KeyValue kv3 =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("3"), Bytes.toBytes("3"));
final long length = kv1.getLength() + Bytes.SIZEOF_INT;
encoder.write(kv1);
encoder.write(kv2);
encoder.write(kv3);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(length * 3, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = kvc.getDecoder(dis);
assertTrue(decoder.advance());
KeyValue kv = (KeyValue)decoder.current();
assertTrue(kv1.equals(kv));
assertTrue(decoder.advance());
kv = (KeyValue)decoder.current();
assertTrue(kv2.equals(kv));
assertTrue(decoder.advance());
kv = (KeyValue)decoder.current();
assertTrue(kv3.equals(kv));
assertFalse(decoder.advance());
dis.close();
assertEquals((length * 3), cis.getCount());
}
示例15: storeChunk
import com.google.common.io.CountingOutputStream; //导入方法依赖的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;
}
}