Package com.google.common.io

Examples of com.google.common.io.CountingOutputStream


            out.flush();
        }

        private OutputStream getCurrentTarget() throws IOException {
            if (currentTarget == null) {
                currentTarget = new CountingOutputStream(outputFactory.get());
            } else if (currentTarget.getCount() >= byteSoftLimit) {
                LOGGER.info(String.format(
                        "Closing stream and opening a new one, reached %,d bytes.\n",
                        currentTarget.getCount()));
                currentTarget.close();
                currentTarget = new CountingOutputStream(outputFactory.get());
            }

            return currentTarget;
        }
View Full Code Here


     * @throws IOException
     * @return the number of objects written
     */
    public long write(OutputStream out, Iterator<DiffEntry> changes) throws IOException {
        final ObjectDatabase objectDatabase = repository.objectDatabase();
        out = new CountingOutputStream(out);

        // avoids sending the same metadata object multiple times
        Set<ObjectId> writtenMetadataIds = new HashSet<ObjectId>();

        // buffer to avoid ObjectId cloning its internal state for each object
View Full Code Here

        private final CountingOutputStream compressed;

        private ReportingOutputStream(HttpURLConnection connection, OutputStream out,
                boolean gzipEncode) {
            super(new CountingOutputStream(out));
            this.gzipEncode = gzipEncode;
            this.connection = connection;
            compressed = (CountingOutputStream) super.out;
            if (gzipEncode) {
                GZIPOutputStream gzipOut;
                try {
                    gzipOut = new GZIPOutputStream(compressed);
                } catch (IOException e) {
                    throw Throwables.propagate(e);
                }
                uncompressed = new CountingOutputStream(gzipOut);
                super.out = uncompressed;
            } else {
                uncompressed = compressed;
            }
        }
View Full Code Here

            this.deduplicator = deduplicator;
        }

        @Override
        public void write(final OutputStream out) throws IOException {
            CountingOutputStream counting = new CountingOutputStream(out);
            OutputStream output = counting;
            try {
                ObjectFunnel funnel;
                funnel = ObjectFunnels.newFunnel(output, DataStreamSerializationFactoryV1.INSTANCE);
                packer.write(funnel, want, have, false, deduplicator);
                counting.flush();
                funnel.close();
            } catch (IOException e) {
                e.printStackTrace();
                throw e;
            } catch (RuntimeException e) {
View Full Code Here

    * @param connection
    *           connection to write to
    */
   void writePayloadToConnection(Payload payload, Object lengthDesc, HttpURLConnection connection) throws IOException {
      connection.setDoOutput(true);
      CountingOutputStream out = new CountingOutputStream(connection.getOutputStream());
      InputStream is = payload.openStream();
      try {
         ByteStreams.copy(is, out);
      } catch (IOException e) {
         logger.error(e, "error after writing %d/%s bytes to %s", out.getCount(), lengthDesc, connection.getURL());
         throw e;
      } finally {
         Closeables.closeQuietly(is);
      }
   }
View Full Code Here

        binaryOutput.writeLong(streamLength);
        currentBinaryStreamLength = streamLength;

        // Wrap our binaryOutput in a CountingOutputStream so that we can
        // validate the length later
        return currentBinaryStream = new CountingOutputStream(new UncloseableOutputStream(binaryOutput));
    }
View Full Code Here

        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

    * @param connection
    *           connection to write to
    */
   void writePayloadToConnection(Payload payload, Object lengthDesc, HttpURLConnection connection) throws IOException {
      connection.setDoOutput(true);
      CountingOutputStream out = new CountingOutputStream(connection.getOutputStream());
      try {
         payload.writeTo(out);
      } catch (IOException e) {
         logger.error(e, "error after writing %d/%s bytes to %s", out.getCount(), lengthDesc, connection.getURL());
         throw e;
      }
   }
View Full Code Here

                @Override
                public void writeTo(OutputStream out)
                        throws IOException
                {
                    try {
                        countingOutputStream = new CountingOutputStream(out);
                        request.getBodyGenerator().write(countingOutputStream);
                    }
                    catch (Exception e) {
                        Throwables.propagateIfPossible(e, IOException.class);
                        throw new IOException(e);
View Full Code Here

                                    final File file = new File(tempDestDir, StringUtils.substringBefore(FilenameUtils.getName(uri), "?"));
                                    HttpEntity entity = response.getEntity();

                                    final long length = entity.getContentLength();

                                    final CountingOutputStream os = new CountingOutputStream(new FileOutputStream(file));

                                    System.out.printf("Downloading %s to %s...%n", uri, file);

                                    Thread progressThread = new Thread(new Runnable() {
                                        double lastProgress;

                                        @Override
                                        public void run() {
                                            while (!Thread.currentThread().isInterrupted()) {
                                                long copied = os.getCount();

                                                double progress = copied * 100D / length;

                                                if (progress != lastProgress) {
                                                    final String s = String.format("%s: %s/%s %s%%",
View Full Code Here

TOP

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

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.