Package org.jwat.common

Examples of org.jwat.common.ByteCountingPushBackInputStream


        if (buffer_size <= 0) {
            throw new IllegalArgumentException(
                    "The 'buffer_size' is less than or equal to zero: "
                    + buffer_size);
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(
                        new BufferedInputStream(in, buffer_size),
                        PUSHBACK_BUFFER_SIZE);
        return new ArcReaderUncompressed(pbin);
    }
View Full Code Here


public class TestWarcReaderFactory_IsWarc {

    @Test
    public void test_iswarc() {
        byte[] bytes;
        ByteCountingPushBackInputStream pbin;
        try {
            /*
             * isWarcFile.
             */
            bytes = WarcConstants.WARC_MAGIC_HEADER.getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertTrue(WarcReaderFactory.isWarcFile(pbin));
            pbin.close();

            bytes = "WARC/1.0".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertTrue(WarcReaderFactory.isWarcFile(pbin));
            pbin.close();

            bytes = WarcConstants.WARC_MAGIC_HEADER.toLowerCase().getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
            pbin.close();

            bytes = "warc/1.0".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
            pbin.close();

            bytes = "WARC".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
            pbin.close();
            /*
             * isWarcRecord.
             */
            bytes = WarcConstants.WARC_MAGIC_HEADER.getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertTrue(WarcReaderFactory.isWarcRecord(pbin));
            pbin.close();

            bytes = "WARC/1.0".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertTrue(WarcReaderFactory.isWarcRecord(pbin));
            pbin.close();

            bytes = WarcConstants.WARC_MAGIC_HEADER.toLowerCase().getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
            pbin.close();

            bytes = "warc/1.0".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
            pbin.close();

            bytes = "WARC".getBytes();
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
            Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
View Full Code Here

    @Test
    public void test_archeader_fields() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream in;
        ByteCountingPushBackInputStream pbin;
        ArcWriter writer;
        ArcReader reader;
        byte[] bytes;
        ArcHeader header;
        boolean success;
View Full Code Here

        if (buffer_size <= 0) {
            throw new IllegalArgumentException(
                    "The 'buffer_size' is less than or equal to zero: " +
                    buffer_size);
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(
                        new BufferedInputStream(in, buffer_size),
                PUSHBACK_BUFFER_SIZE);
        if (GzipReader.isGzipped(pbin)) {
            return new WarcReaderCompressed(new GzipReader(pbin),
                                            buffer_size);
View Full Code Here

    public static WarcReader getReader(InputStream in) throws IOException {
        if (in == null) {
            throw new IllegalArgumentException(
                    "The inputstream 'in' is null");
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(in, PUSHBACK_BUFFER_SIZE);
        if (GzipReader.isGzipped(pbin)) {
            return new WarcReaderCompressed(new GzipReader(pbin));
        }
        return new WarcReaderUncompressed(pbin);
    }
View Full Code Here

                                                        throws IOException {
        if (in == null) {
            throw new IllegalArgumentException(
                    "The inputstream 'in' is null");
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(in, PUSHBACK_BUFFER_SIZE);
        return new WarcReaderUncompressed(pbin);
    }
View Full Code Here

        if (buffer_size <= 0) {
            throw new IllegalArgumentException(
                    "The 'buffer_size' is less than or equal to zero: " +
                    buffer_size);
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(
                        new BufferedInputStream(in, buffer_size),
                PUSHBACK_BUFFER_SIZE);
        return new WarcReaderUncompressed(pbin);
    }
View Full Code Here

                        new Diagnosis(DiagnosisType.INVALID_DATA,
                                "Magic Version string", versionStr));
            }

            MaxLengthRecordingInputStream mrin = new MaxLengthRecordingInputStream(in, reader.recordHeaderMaxSize);
            ByteCountingPushBackInputStream pbin = new ByteCountingPushBackInputStream(mrin, reader.recordHeaderMaxSize);

            parseHeaders(pbin);
            pbin.close();

            checkFields();

            headerBytes = headerBytesOut.toByteArray();
        }
View Full Code Here

        }
        currentRecord = null;
        currentReader = reader;
        currentEntry = reader.getNextEntry();
        if (currentEntry != null) {
            ByteCountingPushBackInputStream pbin;
            if (bufferSize > 0) {
                pbin = new ByteCountingPushBackInputStream(
                        new BufferedInputStream(
                                currentEntry.getInputStream(), bufferSize),
                                PUSHBACK_BUFFER_SIZE);
            }
            else {
                pbin = new ByteCountingPushBackInputStream(
                        currentEntry.getInputStream(), PUSHBACK_BUFFER_SIZE);
            }
            currentRecord = WarcRecord.parseRecord(pbin, this);
        }
        if (currentRecord != null) {
View Full Code Here

        }
        currentRecord = null;
        currentReader = new GzipReader(rin);
        currentEntry = currentReader.getNextEntry();
        if (currentEntry != null) {
            ByteCountingPushBackInputStream pbin =
                    new ByteCountingPushBackInputStream(
                            currentEntry.getInputStream(), PUSHBACK_BUFFER_SIZE);
            currentRecord = WarcRecord.parseRecord(pbin, this);
        }
        if (currentRecord != null) {
            startOffset = offset;
View Full Code Here

TOP

Related Classes of org.jwat.common.ByteCountingPushBackInputStream

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.