Guava CountingInputStream - 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 CountingInputStream class.

This code example shows how to use the following methods:getCount
    public void init() { 
        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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
    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());
  } 
 
  @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);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
        this.sorter = sorter;
    } 
 
    public void sort(InputStream inputStream, OutputStream outputStream) {
        long begin = System.currentTimeMillis();
        CountingInputStream countingInputStream = new CountingInputStream(inputStream);
        doSort(countingInputStream, outputStream);
        LogUtils.infoTimeTaken(LOG, begin, countingInputStream.getCount(), "Sorted stream of %d bytes", countingInputStream.getCount());
    } 
 
    private void doSort(InputStream inputStream, OutputStream outputStream ) {
        try { 
            sorter.sort(inputStream,outputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
    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());
  } 
 
  @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);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
    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());
  } 
 
  @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);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    public UncompressedWARCReader(final String f, final InputStream is, 
            final boolean atFirstRecord) 
        throws IOException { 
            // Arc file has been tested for existence by time it has come 
            // to here. 
            setIn(new CountingInputStream(is)); 
            setCompressed(true); 
            initialize(f); 
        } 
         
 
	public static WARCReader get(String arc, InputStream is, boolean atFirstRecord ) throws IOException { 
		return new UncompressedWARCReader(arc, is, atFirstRecord); 
	} 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    public UncompressedARCReader(final String f, final InputStream is, 
            final boolean atFirstRecord) 
        throws IOException { 
            // Arc file has been tested for existence by time it has come 
            // to here. 
            setIn(new CountingInputStream(is)); 
            setCompressed(true); 
            setAlignedOnFirstRecord(atFirstRecord); 
            initialize(f); 
        } 
         
 
	public static ARCReader get(String arc, InputStream is, boolean atFirstRecord ) throws IOException { 
		return new UncompressedARCReader(arc, is, atFirstRecord); 
	} 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
  public String getMessageDigest() {
    return Hex.encode(messageDigest.digest());
  } 
 
  public long getSize() { 
    return countingInputStream.getCount();
  } 
 
  public StreamMetrics getMetrics() { 
    return new StreamMetrics(getSize(), getMessageDigest()); 
  } 
 
  private static MessageDigest createSha1() {
    try { 
      return MessageDigest.getInstance("SHA1");
    } 
    catch (NoSuchAlgorithmException e) {
      // should never happen 
      throw Throwables.propagate(e);
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
    } 
 
    @Override 
    public long getBytesRead() 
    { 
        return countingInputStream.getCount();
    } 
 
    @Override 
    public InputStream getInputStream()
            throws IOException
    { 
        return countingInputStream;
    } 
 
    @Override 
    public String toString()
    { 
        return toStringHelper(this)
                .add("statusCode", getStatusCode())
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCount
    } 
 
    @Override 
    public long getBytesRead() 
    { 
        return countingInputStream.getCount();
    } 
 
    @Override 
    public InputStream getInputStream()
            throws IOException
    { 
        return countingInputStream;
    } 
 
    @Override 
    public String toString()
    { 
        return toStringHelper(this)
                .add("statusCode", getStatusCode())
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava CountingInputStream Methods: