Package com.google.common.io

Examples of com.google.common.io.CountingInputStream


      StorageFileItem primaryItem = (StorageFileItem) repository.retrieveItem(
          false, new ResourceStoreRequest("/" + primaryPath)
      );
      try (InputStream in = primaryItem.getInputStream();
           CountingInputStream cis = new CountingInputStream(new GZIPInputStream(new BufferedInputStream(in)))) {
        primaryEl.getElementsByTagName("open-checksum").item(0).setTextContent(String.valueOf(
            getDigest("SHA-256", cis)
        ));
        primaryEl.getElementsByTagName("open-size").item(0).setTextContent(String.valueOf(
            cis.getCount()
        ));
      }

      primaryItem = (StorageFileItem) repository.retrieveItem(
          false, new ResourceStoreRequest("/" + primaryPath)
      );
      try (InputStream in = primaryItem.getInputStream();
           CountingInputStream cis = new CountingInputStream(new BufferedInputStream(in))) {
        primaryEl.getElementsByTagName("checksum").item(0).setTextContent(String.valueOf(
            getDigest("SHA-256", cis)
        ));
        primaryEl.getElementsByTagName("size").item(0).setTextContent(String.valueOf(
            cis.getCount()
        ));
      }

      ((Element) primaryEl.getElementsByTagName("location").item(0)).setAttribute("href", primaryPath);
View Full Code Here


  private final MessageDigest messageDigest;

  private final CountingInputStream countingInputStream;

  public MetricsInputStream(final InputStream input) {
    this(new CountingInputStream(input), createSha1());
  }
View Full Code Here

    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));
    List<Tag> tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(2, tags.size());
    Tag tag = tags.get(0);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring1"), tag.getValue()));
    tag = tags.get(1);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring2"), tag.getValue()));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellComparator.equals(c, kv2));
    tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(1, tags.size());
    tag = tags.get(0);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring3"), tag.getValue()));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellComparator.equals(c, kv3));
    tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(3, tags.size());
    tag = tags.get(0);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring4"), tag.getValue()));
    tag = tags.get(1);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring5"), tag.getValue()));
    tag = tags.get(2);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring6"), tag.getValue()));
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(offset, cis.getCount());
  }
View Full Code Here

    encoder.write(cell2);
    encoder.write(cell3);
    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, cell1));
    List<Tag> tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(2, tags.size());
    Tag tag = tags.get(0);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring1"), tag.getValue()));
    tag = tags.get(1);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring2"), tag.getValue()));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellComparator.equals(c, cell2));
    tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(1, tags.size());
    tag = tags.get(0);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring3"), tag.getValue()));
    assertTrue(decoder.advance());
    c = decoder.current();
    assertTrue(CellComparator.equals(c, cell3));
    tags = Tag.asList(c.getTagsArray(), c.getTagsOffset(), c.getTagsLengthUnsigned());
    assertEquals(3, tags.size());
    tag = tags.get(0);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring4"), tag.getValue()));
    tag = tags.get(1);
    assertEquals(2, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring5"), tag.getValue()));
    tag = tags.get(2);
    assertEquals(1, tag.getType());
    assertTrue(Bytes.equals(Bytes.toBytes("teststring6"), tag.getValue()));
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(offset, cis.getCount());
  }
View Full Code Here

        private CountingInputStream uncompressed;

        private CountingInputStream compressed;

        private ReportingInputStream(InputStream in, boolean isGzipEncoded) {
            super(new CountingInputStream(in));
            this.isGzipEncoded = isGzipEncoded;
            if (isGzipEncoded) {
                compressed = (CountingInputStream) super.in;
                GZIPInputStream gzipIn;
                try {
                    gzipIn = new GZIPInputStream(compressed);
                } catch (IOException e) {
                    throw Throwables.propagate(e);
                }
                uncompressed = new CountingInputStream(gzipIn);
                super.in = uncompressed;
            } else {
                uncompressed = ((CountingInputStream) super.in);
                compressed = uncompressed;
            }
View Full Code Here

            input = representation.getStream();
            final GeoGIG ggit = getGeogig(request).get();
            final BinaryPackedObjects unpacker = new BinaryPackedObjects(ggit.getRepository()
                    .objectDatabase());

            CountingInputStream countingStream = new CountingInputStream(input);

            Stopwatch sw = Stopwatch.createStarted();
            IngestResults ingestResults = unpacker.ingest(countingStream);
            sw.stop();

            LOGGER.info(String
                    .format("SendObjectResource: Processed %,d objects.\nInserted: %,d.\nExisting: %,d.\nTime to process: %s.\nStream size: %,d bytes.\n",
                            ingestResults.total(), ingestResults.getInserted(),
                            ingestResults.getExisting(), sw, countingStream.getCount()));

        } catch (IOException e) {
            LOGGER.warn("Error processing incoming objects from {}", request.getClientInfo()
                    .getAddress(), e);
            throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e);
View Full Code Here

    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());
        }
    }
View Full Code Here

    public TestingResponse(HttpStatus status, ListMultimap<String, String> headers, InputStream input)
    {
        this.status = checkNotNull(status, "status is null");
        this.headers = ImmutableListMultimap.copyOf(checkNotNull(headers, "headers is null"));
        this.countingInputStream = new CountingInputStream(checkNotNull(input, "input is null"));
    }
View Full Code Here

        private final CountingInputStream inputStream;

        public JettyResponse(Response response, InputStream inputStream)
        {
            this.response = response;
            this.inputStream = new CountingInputStream(inputStream);
        }
View Full Code Here

        private final CountingInputStream inputStream;

        public JettyResponse(Response response, InputStream inputStream)
        {
            this.response = response;
            this.inputStream = new CountingInputStream(inputStream);
        }
View Full Code Here

TOP

Related Classes of com.google.common.io.CountingInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.