Package com.google.common.io

Examples of com.google.common.io.CountingOutputStream


            File file = new File(tempDestDir, optional.get().name);
            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) {
                            System.out.printf("\rProgress: %s%%", LangUtils.toConciseString(progress, 1));
View Full Code Here


            File file = new File(tempDestDir, optional.get().name);
            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) {
                            System.out.printf("\rProgress: %s%%", LangUtils.toConciseString(progress, 1));
View Full Code Here

    private long measureSerializedSize(final Object attribute)
            throws IOException {
        final Closer closer = Closer.create();
        try {
            final CountingOutputStream countingStream = closer
                    .register(new CountingOutputStream(ByteStreams
                            .nullOutputStream()));
            final ObjectOutputStream out = closer
                    .register(new ObjectOutputStream(countingStream));
            out.writeObject(attribute);
            return countingStream.getCount();
        } finally {
            closer.close();
        }
    }
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 {
         closeQuietly(is);
      }
   }
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.