Package org.apache.commons.io.output

Examples of org.apache.commons.io.output.DeferredFileOutputStream


    * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification.
    * @throws IOException -
    */
   private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientInvocation request) throws IOException
   {
      DeferredFileOutputStream memoryManagedOutStream =
              new DeferredFileOutputStream(this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(),
                      getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir);
      request.getDelegatingOutputStream().setDelegate(memoryManagedOutStream);
      request.writeRequestBody(request.getEntityStream());
      memoryManagedOutStream.close();
      return memoryManagedOutStream;
   }
View Full Code Here


    * @throws IOException -
    */
   protected HttpEntity buildEntity(final ClientRequest request) throws IOException
   {
      HttpEntity entityToBuild = null;
      DeferredFileOutputStream memoryManagedOutStream = writeRequestBodyToOutputStream(request);

      if (memoryManagedOutStream.isInMemory())
      {
         ByteArrayEntity entityToBuildByteArray = new ByteArrayEntity(memoryManagedOutStream.getData());
         entityToBuildByteArray.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getBodyContentType().toString()));
         entityToBuild = entityToBuildByteArray;
      }
      else
      {
         File requestBodyFile = memoryManagedOutStream.getFile();
         requestBodyFile.deleteOnExit();
         entityToBuild = new FileExposingFileEntity(memoryManagedOutStream.getFile(), request.getBodyContentType().toString());
      }

      return entityToBuild;
   }
View Full Code Here

    * @return - DeferredFileOutputStream with the ClientRequest written out per HTTP specification.
    * @throws IOException -
    */
   private DeferredFileOutputStream writeRequestBodyToOutputStream(final ClientRequest request) throws IOException
   {
      DeferredFileOutputStream memoryManagedOutStream =
              new DeferredFileOutputStream(this.fileUploadInMemoryThresholdLimit * getMemoryUnitMultiplier(),
                      getTempfilePrefix(), ".tmp", this.fileUploadTempFileDir);
      request.writeRequestBody(request.getHeadersAsObjects(), memoryManagedOutStream);
      memoryManagedOutStream.close();
      return memoryManagedOutStream;
   }
View Full Code Here

            if (dfos == null) {
                File outputFile = null;
                if (sizeThreshold != Integer.MAX_VALUE) {
                    outputFile = getTempFile();
                }
                dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
            }
            return dfos;
        }
View Full Code Here

        File tempFile = null;
        try {
            // Can't be bigger than int, since it's the max of the above allocation
            int size = (int)chunk.getSize();
            tempFile = File.createTempFile("ResultSpooler",".bin");
            DeferredFileOutputStream spoolTo = new DeferredFileOutputStream(size, tempFile) {
                @Override
                protected void thresholdReached() throws IOException {
                    super.thresholdReached();
                    chunk.close();
                }
            };
            DataOutputStream out = new DataOutputStream(spoolTo);
            final long maxBytesAllowed = maxSpoolToDisk == -1 ?
                Long.MAX_VALUE : thresholdBytes + maxSpoolToDisk;
            long bytesWritten = 0L;
            int maxSize = 0;
            for (Tuple result = scanner.next(); result != null; result = scanner.next()) {
                int length = TupleUtil.write(result, out);
                bytesWritten += length;
                if(bytesWritten > maxBytesAllowed){
                    throw new SpoolTooBigToDiskException("result too big, max allowed(bytes): " + maxBytesAllowed);
                }
                maxSize = Math.max(length, maxSize);
            }
            spoolTo.close();
            if (spoolTo.isInMemory()) {
                byte[] data = spoolTo.getData();
                chunk.resize(data.length);
                spoolFrom = new InMemoryResultIterator(data, chunk);
            } else {
                spoolFrom = new OnDiskResultIterator(maxSize, spoolTo.getFile());
                usedOnDiskIterator = true;
            }
            success = true;
        } catch (IOException e) {
            throw ServerUtil.parseServerException(e);
View Full Code Here

            if (dfos == null) {
                File outputFile = null;
                if (sizeThreshold != Integer.MAX_VALUE) {
                    outputFile = getTempFile();
                }
                dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
            }
            return dfos;
        }
View Full Code Here

    public MimeMessageInputStreamSource(String key, InputStream in) throws MessagingException {
        super();
        // We want to immediately read this into a temporary file
        // Create a temp file and channel the input stream into it
        try {
            out = new DeferredFileOutputStream(THRESHOLD, key, ".m64", TMPDIR);
            IOUtils.copy(in, out);
            sourceId = key;
        } catch (IOException ioe) {
            throw new MessagingException("Unable to retrieve the data: " + ioe.getMessage(), ioe);
        } finally {
View Full Code Here

        }
    }

    public MimeMessageInputStreamSource(String key) {
        super();
        out = new DeferredFileOutputStream(THRESHOLD, key, ".m64", TMPDIR);
        sourceId = key;
    }
View Full Code Here

                sizeThreshold = Integer.MAX_VALUE;
            } else {
                sizeThreshold = this.sizeThreshold;
            }

            dfos = new DeferredFileOutputStream(sizeThreshold, "upload_" + UID, ".tmp", repository);
        }
        return dfos;
    }
View Full Code Here

                sizeThreshold = Integer.MAX_VALUE;
            } else {
                sizeThreshold = this.sizeThreshold;
            }

            dfos = new DeferredFileOutputStream(sizeThreshold, "upload_" + UID, ".tmp", repository);
        }
        return dfos;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.io.output.DeferredFileOutputStream

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.