Package org.apache.commons.io.output

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


      LOG.debug("Starting new record; id=" + curEntryId
          + "; claimedLen=" + claimedLen);
      WritableUtils.writeVLong(out, curEntryId);
      WritableUtils.writeVLong(out, claimedLen);
      this.curClaimedLen = claimedLen;
      this.userCountingOutputStream = new CountingOutputStream(
          new CloseShieldOutputStream(out));
      if (null == this.codec) {
        // No codec; pass thru the same OutputStream to the user.
        this.userOutputStream = this.userCountingOutputStream;
      } else {
View Full Code Here


    }

    OutputStream fsOut = fs.create(destFile);

    // Count how many actual bytes hit HDFS.
    this.countingFilterStream = new CountingOutputStream(fsOut);

    if (codec != null) {
      // Wrap that in a compressing stream.
      this.writeStream = codec.createOutputStream(this.countingFilterStream);
    } else {
View Full Code Here

        out.write(buf);
        bytesWritten += buf.length;
       
        //Stream contents
        CloseBlockerOutputStream cbout = new CloseBlockerOutputStream(out);
        CountingOutputStream cout = new CountingOutputStream(cbout);
        OutputStream filteredOutput =
                getFilterList().applyFilters(cout);
        outputRawStreamData(filteredOutput);
        filteredOutput.close();
        refLength.setNumber(new Integer(cout.getCount()));
        bytesWritten += cout.getCount();
           
        //Stream trailer
        buf = encode("\nendstream");
        out.write(buf);
        bytesWritten += buf.length;
View Full Code Here

                        }
                    }
                };
            }
            else {
                out = new CountingOutputStream(NullOutputStream.NULL_OUTPUT_STREAM) {
                    @Override
                    public void close() throws IOException {
                        super.close();
                        final long byteCount = this.getByteCount();
                        if (byteCount > 0) {
View Full Code Here

            if(null != templateRegex) builder.setTemplateRegex(templateRegex);
            if(null != templateValueConstraintRegex) builder.setTemplateValueConstraintRegex(templateValueConstraintRegex);
            if(null != typeIdMapJson) builder.setTypeIdMap(parseTypeIdMap(typeIdMapJson));
            if(null != templateFile) builder.setFreemarkerTemplate(FileUtils.readFileToString(templateFile, templateFileEncoding));
            CodeGenerator cg = builder.build();
            CountingOutputStream counter = new CountingOutputStream(openOutputStream(outFile));
            outWriter = new OutputStreamWriter(counter, "UTF-8");
            getLog().info("Generating queries wrapper for file: [" + queriesFile.getAbsolutePath() + "] " +
                    "into java file: [" + outFile.getAbsolutePath() + "]");
            cg.generate(queries, fcn, queriesFile.getName(), outWriter);
            getLog().info("Writing compete, bytes written: [" + counter.getCount() + "]");
        } catch(IOException e) {
            throw new MojoFailureException("IO error", e);
        } catch (ClassNotFoundException e) {
            throw new MojoFailureException("Type id map error", e);
        } finally {
View Full Code Here

            if(null != selectRegex) builder.setSelectRegex(selectRegex);
            if(null != updateRegex) builder.setUpdateRegex(updateRegex);
            if(null != typeIdMapJson) builder.setTypeIdMap(parseTypeIdMap(typeIdMapJson));
            if(null != templateFile) builder.setFreemarkerTemplate(FileUtils.readFileToString(templateFile, templateFileEncoding));
            CodeGenerator cg = builder.build();
            CountingOutputStream counter = new CountingOutputStream(openOutputStream(outFile));
            outWriter = new OutputStreamWriter(counter, "UTF-8");
            getLog().info("Generating queries wrapper for file: [" + queriesFile.getAbsolutePath() + "] " +
                    "into java file: [" + outFile.getAbsolutePath() + "]");
            cg.generate(queries, fcn, queriesFile.getName(), outWriter);
            getLog().info("Writing compete, bytes written: [" + counter.getCount() + "]");
        } catch(IOException e) {
            throw new MojoFailureException("IO error", e);
        } catch (ClassNotFoundException e) {
            throw new MojoFailureException("Type id map error", e);
        } finally {
View Full Code Here

    @Override
    public void writeTo(OutputStream out, String[] ignoreHeaders)
            throws MessagingException, IOException {
        if (bytesSent == -1) {
            CountingOutputStream countingOut = new CountingOutputStream(out);
            super.writeTo(countingOut, ignoreHeaders);
            bytesSent = countingOut.getByteCount();
        } else {
            super.writeTo(out, ignoreHeaders);
        }
    }
View Full Code Here

  private void doGzipResponse(final HttpServletRequest req, final HttpServletResponse response, final FilterChain chain)
      throws IOException, ServletException {
    LOG.debug("Applying gzip on resource: " + req.getRequestURI());
    response.setHeader(HttpHeader.CONTENT_ENCODING.toString(), "gzip");
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final CountingOutputStream countingStream = new CountingOutputStream(new GZIPOutputStream(new BufferedOutputStream(
        baos)));
    // final GZIPOutputStream gzout = new GZIPOutputStream(new BufferedOutputStream(baos));
    // Perform gzip operation in-memory before sending response
    final HttpServletResponseWrapper wrappedResponse = new RedirectedStreamServletResponseWrapper(countingStream,
        response);
    chain.doFilter(req, wrappedResponse);
    // close underlying stream
    countingStream.close();
    response.setContentLength(countingStream.getCount());
    // avoid NO CONTENT error thrown by jetty when gzipping empty response
    if (countingStream.getCount() > 0) {
      IOUtils.write(baos.toByteArray(), response.getOutputStream());
    }
  }
View Full Code Here

        out.write(buf);
        bytesWritten += buf.length;

        //Stream contents
        CloseBlockerOutputStream cbout = new CloseBlockerOutputStream(out);
        CountingOutputStream cout = new CountingOutputStream(cbout);
        OutputStream filteredOutput = getFilterList().applyFilters(cout);
        outputRawStreamData(filteredOutput);
        filteredOutput.close();
        refLength.setNumber(Integer.valueOf(cout.getCount()));
        bytesWritten += cout.getCount();

        //Stream trailer
        buf = encode("\nendstream");
        out.write(buf);
        bytesWritten += buf.length;
View Full Code Here

     */
    @Override
    public int output(OutputStream stream) throws IOException {
        setupFilterList();

        CountingOutputStream cout = new CountingOutputStream(stream);
        StringBuilder textBuffer = new StringBuilder(64);

        StreamCache encodedStream = null;
        PDFNumber refLength = null;
        final Object lengthEntry;
        if (encodeOnTheFly) {
            refLength = new PDFNumber();
            getDocumentSafely().registerObject(refLength);
            lengthEntry = refLength;
        } else {
            encodedStream = encodeStream();
            lengthEntry = Integer.valueOf(encodedStream.getSize() + 1);
        }

        populateStreamDict(lengthEntry);
        dictionary.writeDictionary(cout, textBuffer);

        //Send encoded stream to target OutputStream
        PDFDocument.flushTextBuffer(textBuffer, cout);
        if (encodedStream == null) {
            encodeAndWriteStream(cout, refLength);
        } else {
            outputStreamData(encodedStream, cout);
            encodedStream.clear(); //Encoded stream can now be discarded
        }

        PDFDocument.flushTextBuffer(textBuffer, cout);
        return cout.getCount();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.io.output.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.