Package com.google.common.io

Examples of com.google.common.io.FileBackedOutputStream


    if (encryptionHandler != null)
    {
      byte[] iv = getCipherIVFromBlobName(blobName);
     
      InputStream encryptedInputStream = this.encryptionHandler.encrypt(in, Configurator.getBlobStoreDefaultEncryptionKey(), iv);
      FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true);
     
      updatedSize = ByteStreams.copy(encryptedInputStream, fbout);
      in1 = fbout.getSupplier().getInput();

      blobUri.setEncryptionKey(Configurator.getBlobStoreDefaultEncryptionKeyAlias());
    } else {
      in1 = in;
    }
View Full Code Here


    // compress stream and calculate compressed size
    if ((compressionHandler != null) && (size > MIN_COMPRESS_SIZE))
    {
      InputStream compressedInputStream = compressionHandler.compress(in);
      FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true);
      updatedSize = ByteStreams.copy(compressedInputStream, fbout);
      in1 = fbout.getSupplier().getInput();
      compressed = true;
    } else {
      in1 = in;
    }
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      final FileBackedOutputStream out = new FileBackedOutputStream(limit);
      try {
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         InputStream is = out.asByteSource().openStream();
         try {
            wire(header, is);
         } finally {
            is.close();
         }
         // we must call FileBackedOutputStream.reset to remove temporary file
         return new FilterInputStream(out.asByteSource().getInput()) {
            @Override
            public void close() throws IOException {
               super.close();
               out.reset();
            }
         };
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      final FileBackedOutputStream out = new FileBackedOutputStream(limit);
      try {
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         wire(header, out.asByteSource().getInput());
         // we must call FileBackedOutputStream.reset to remove temporary file
         return new FilterInputStream(out.asByteSource().getInput()) {
            @Override
            public void close() throws IOException {
               super.close();
               out.reset();
            }
         };
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      FileBackedOutputStream out = null;
      try {
         out = new FileBackedOutputStream(limit);
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         wire(header, out.getSupplier().getInput());
         return out.getSupplier().getInput();
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
         closeQuietly(out);
         closeQuietly(instream);
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      final FileBackedOutputStream out = new FileBackedOutputStream(limit);
      try {
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         wire(header, out.getSupplier().getInput());
         // we must call FileBackedOutputStream.reset to remove temporary file
         return new FilterInputStream(out.getSupplier().getInput()) {
            @Override
            public void close() throws IOException {
               super.close();
               out.reset();
            }
         };
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
View Full Code Here

     */
    private final InputSupplier<InputStream> supplier;
    private final long length;

    FileBackedInputStreamFactory(byte[] data) throws IOException {
      FileBackedOutputStream out =
          new FileBackedOutputStream(IN_MEMORY_THRESHOLD, true);
      length = data.length;
      out.write(data);
      out.close();
      supplier = out.getSupplier();
    }
View Full Code Here

        // not used, we're getting the whole command and args in the "method" object
        // JsonArray paramsArray = json.get("params").getAsJsonArray();

        InputStream in = new ByteArrayInputStream(new byte[0]);
        // dumps output to a temp file if > threshold
        FileBackedOutputStream out = new FileBackedOutputStream(4096);
        try {
            // pass it a BufferedOutputStream 'cause it doesn't buffer the internal FileOutputStream
            ConsoleReader console = new ConsoleReader(in, new BufferedOutputStream(out),
                    new UnsupportedTerminal());
            Platform platform = geogig.getPlatform();

            GeogigCLI geogigCLI = new GeogigCLI(geogig, console);
            geogigCLI.setPlatform(platform);
            geogigCLI.disableProgressListener();

            String[] args = ArgumentTokenizer.tokenize(command);
            final int exitCode = geogigCLI.execute(args);
            response = new JsonObject();
            response.addProperty("id", queryId);

            final int charCountLimit = getOutputLimit(geogig.getContext());
            final StringBuilder output = getLimitedOutput(out, charCountLimit);

            if (exitCode == 0) {
                response.addProperty("result", output.toString());
                response.addProperty("error", (String) null);
            } else {
                Exception exception = geogigCLI.exception;
                JsonObject error = buildError(exitCode, output, exception);
                response.add("error", error);
            }
            return response;
        } catch (IOException e) {
            throw Throwables.propagate(e);
        } finally {
            // delete temp file
            try {
                out.reset();
            } catch (IOException ignore) {
                ignore.printStackTrace();
            }
        }
    }
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      final FileBackedOutputStream out = new FileBackedOutputStream(limit);
      try {
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         InputStream is = out.asByteSource().openStream();
         try {
            wire(header, is);
         } finally {
            is.close();
         }
         // we must call FileBackedOutputStream.reset to remove temporary file
         return new FilterInputStream(out.asByteSource().openStream()) {
            @Override
            public void close() throws IOException {
               super.close();
               out.reset();
            }
         };
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
View Full Code Here

      return getWireLog().isDebugEnabled();
   }

   public InputStream copy(final String header, InputStream instream) {
      int limit = 256 * 1024;
      final FileBackedOutputStream out = new FileBackedOutputStream(limit);
      try {
         long bytesRead = ByteStreams.copy(instream, out);
         if (bytesRead >= limit)
            logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit);
         wire(header, out.getSupplier().getInput());
         // we must call FileBackedOutputStream.reset to remove temporary file
         return new FilterInputStream(out.getSupplier().getInput()) {
            @Override
            public void close() throws IOException {
               super.close();
               out.reset();
            }
         };
      } catch (IOException e) {
         throw new RuntimeException("Error tapping line", e);
      } finally {
View Full Code Here

TOP

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

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.