Guava CountingOutputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava CountingOutputStream class.

This code example shows how to use the following methods:getCount
        Monitors.registerObject(this);
    } 
 
    public void handle(HttpExchange exchange) throws IOException {
        CountingInputStream input = new CountingInputStream(exchange.getRequestBody());
        CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody());
        exchange.setStreams(input, output);
        Stopwatch stopwatch = latency.start();
        try { 
            handleImpl(exchange);
        } finally { 
            stopwatch.stop();
            bytesReceived.increment(input.getCount());
            bytesSent.increment(output.getCount());
        } 
    } 
 
    protected abstract void handleImpl(HttpExchange exchange) throws IOException;
} 
7
CodeRank
This code example shows how to use the following methods:getCount
  public static final Log LOG = LogFactory.getLog(TestCellMessageCodec.class);
 
  @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());
  } 
6
CodeRank
This code example shows how to use the following methods:getCount
public class TestCellCodec { 
 
  @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
CodeRank
This code example shows how to use the following methods:getCount
@Category({MiscTests.class, SmallTests.class}) 
public class TestKeyValueCodec { 
  @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());
6
CodeRank
This code example shows how to use the following methods:flush
 
	public void write(InputStream is) throws IOException {
		CRCInputStream crc = new CRCInputStream(is);
		GZIPHeader gzHeader = new GZIPHeader();
		// TODO: add fields... 
		gzHeader.writeBytes(out);
		Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
		DeflaterOutputStream deflateOut = new DeflaterOutputStream(out,deflater);
		StreamCopy.copy(crc, deflateOut);
		deflateOut.finish();
		GZIPFooter gzFooter = new GZIPFooter(crc.getCRCValue(), crc.getByteCount());
		gzFooter.writeBytes(out);
		out.flush();
	} 
 
	public long getBytesWritten() { 
		return out.getCount();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getCount
		this.out = new PrintStream(out);
	} 
 
	public void output(Resource resource) throws IOException {
		OutputStream nullo = ByteStreams.nullOutputStream();
		CountingOutputStream co = new CountingOutputStream(nullo);
		StreamCopy.copy(resource.getInputStream(), co);
		long bytes = co.getCount();
		if(bytes > 0) {
			LOG.info(bytes + " unconsumed bytes in Resource InputStream.");
		} 
		try { 
			out.println(resource.getMetaData().getTopMetaData().toString(1));
		} catch (JSONException e) {
			LOG.warning(e.getMessage());
		}		 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getCount
    } 
 
    @Override 
    public long getLength() throws IOException {
        assert this.mCountingStream != null;
        return this.mCountingStream.getCount();
    } 
 
    @Override 
    public void write(KeyValue keyValue) throws IOException {
        assert this.mWriter != null;
        this.mWriter.write(keyValue.getValue());
        this.mWriter.write(DELIMITER);
    } 
 
    @Override 
    public KeyValue next() throws IOException {
        assert this.mReader != null;
        ByteArrayOutputStream messageBuffer = new ByteArrayOutputStream();
        int nextByte;
3
CodeRank
This code example shows how to use the following methods:getCount
    } 
 
    @Override 
    public int size() 
    { 
        return Ints.checkedCast(countingOutputStream.getCount());
    } 
 
    @Override 
    public int writableBytes() 
    { 
        return Integer.MAX_VALUE;
    } 
 
    @Override 
    public boolean isWritable() 
    { 
        return true; 
    } 
 
3
CodeRank
See Code Examples for Guava CountingOutputStream Methods: