Package org.apache.commons.io.input

Examples of org.apache.commons.io.input.CountingInputStream


     * @throws IOException if an I/O error occurs.
     */
    public BundleReader(BundleBinding binding, InputStream stream)
            throws IOException {
        this.binding = binding;
        this.cin = new CountingInputStream(stream);
        this.in = new DataInputStream(cin);
        this.version = in.readUnsignedByte();
    }
View Full Code Here


    }
   
    void reset() throws IOException {
        bufferedIn.reset();
        bufferedIn.mark(1024 * 1024);
        this.cin = new CountingInputStream(bufferedIn);
        this.in = new DataInputStream(cin);
        this.version = in.readUnsignedByte();
        namespaces = new String[]
                // NOTE: The length of this array must be seven
                { Name.NS_DEFAULT_URI, null, null, null, null, null, null };
View Full Code Here

            // Request sent. Now get the response:
            InputStream instream = httpMethod.getResponseBodyAsStream();

            if (instream != null) {// will be null for HEAD
                instream = new CountingInputStream(instream);
                try {
                    Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
                    if (responseHeader!= null && ENCODING_GZIP.equals(responseHeader.getValue())) {
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                       
View Full Code Here

        // works OK even if ContentEncoding is null
        boolean gzipped = ENCODING_GZIP.equals(conn.getContentEncoding());
        InputStream instream = null;
        try {
            instream = new CountingInputStream(conn.getInputStream());
            if (gzipped) {
                in = new BufferedInputStream(new GZIPInputStream(instream));
            } else {
                in = new BufferedInputStream(instream);
            }
View Full Code Here

  private CountingInputStream countingIn;
  private long maxBytes;

  public FixedLengthInputStream(InputStream stream, long maxLen) {
    super(new CountingInputStream(new CloseShieldInputStream(stream)));

    // Save a correctly-typed reference to the underlying stream.
    this.countingIn = (CountingInputStream) this.in;
    this.maxBytes = maxLen;
  }
View Full Code Here

//
//        return omDocument;
//    }

    public void testBuild() throws Exception {
        CountingInputStream in = new CountingInputStream(getTestResource(
                TestConstants.REALLY_BIG_MESSAGE));
        OMDocument doc = new StAXOMBuilder(omMetaFactory.getOMFactory(),
                XMLInputFactory.newInstance().createXMLStreamReader(in)).getDocument();
        assertFalse(doc.isComplete());
        int countBeforeBuild = in.getCount();
        doc.build();
        assertTrue(doc.isComplete());
        int countAfterBuild = in.getCount();
        assertTrue(countAfterBuild > countBeforeBuild);
        OMNode node = doc.getFirstOMChild();
        while (node != null) {
            node = node.getNextOMSibling();
        }
        assertEquals(countAfterBuild, in.getCount());
    }
View Full Code Here

            // Request sent. Now get the response:
            InputStream instream = httpMethod.getResponseBodyAsStream();

            if (instream != null) {// will be null for HEAD
                instream = new CountingInputStream(instream);
                try {
                    Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
                    if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) {
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                       
View Full Code Here

        // works OK even if ContentEncoding is null
        boolean gzipped = HTTPConstants.ENCODING_GZIP.equals(conn.getContentEncoding());
        InputStream instream = null;
        try {
            instream = new CountingInputStream(conn.getInputStream());
            if (gzipped) {
                in = new BufferedInputStream(new GZIPInputStream(instream));
            } else {
                in = new BufferedInputStream(instream);
            }
View Full Code Here

     * @return the bytes to skip when reading the event file
     *
     * @throws IOException when the {@link #eventFile} was closed unexpectedly
     */
    private long calculateOffset(DomainEventMessage snapshotEvent) throws IOException {
        CountingInputStream countingInputStream = null;
        try {
            countingInputStream = new CountingInputStream(new BufferedInputStream(eventFile));
            FileSystemEventMessageReader eventMessageReader =
                    new FileSystemEventMessageReader(new DataInputStream(countingInputStream));

            long lastReadSequenceNumber = -1;
            while (lastReadSequenceNumber < snapshotEvent.getSequenceNumber()) {
                SerializedDomainEventData entry = eventMessageReader.readEventMessage();
                lastReadSequenceNumber = entry.getSequenceNumber();
            }

            return countingInputStream.getByteCount();
        } finally {
            IOUtils.closeQuietly(countingInputStream);
        }
    }
View Full Code Here

                    rs = null;
                }
            }
            MessageDigest digest = getDigest();
            DigestInputStream dIn = new DigestInputStream(stream, digest);
            CountingInputStream in = new CountingInputStream(dIn);
            StreamWrapper wrapper;
            if (STORE_SIZE_MINUS_ONE.equals(storeStream)) {
                wrapper = new StreamWrapper(in, -1);
            } else if (STORE_SIZE_MAX.equals(storeStream)) {
                wrapper = new StreamWrapper(in, Integer.MAX_VALUE);
            } else if (STORE_TEMP_FILE.equals(storeStream)) {
                File temp = moveToTempFile(in);
                long length = temp.length();
                wrapper = new StreamWrapper(new ResettableTempFileInputStream(temp), length);
            } else {
                throw new DataStoreException("Unsupported stream store algorithm: " + storeStream);
            }
            // UPDATE DATASTORE SET DATA=? WHERE ID=?
            conHelper.exec(updateDataSQL, wrapper, tempId);
            long length = in.getByteCount();
            DataIdentifier identifier =
                    new DataIdentifier(encodeHexString(digest.digest()));
            usesIdentifier(identifier);
            String id = identifier.toString();
            long newModified;
View Full Code Here

TOP

Related Classes of org.apache.commons.io.input.CountingInputStream

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.