Package org.jwat.common

Examples of org.jwat.common.ByteCountingPushBackInputStream


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


        }
        if (offset < -1) {
            throw new IllegalArgumentException(
                    "The 'offset' is less than -1: " + offset);
        }
        ByteCountingPushBackInputStream pbin =
                new ByteCountingPushBackInputStream(rin, PUSHBACK_BUFFER_SIZE);
        currentRecord = WarcRecord.parseRecord(pbin, this);
        if (currentRecord != null) {
            startOffset = offset;
            currentRecord.header.startOffset = offset;
        }
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(rin, buffer_size),
                        PUSHBACK_BUFFER_SIZE);
        currentRecord = WarcRecord.parseRecord(pbin, this);
        if (currentRecord != null) {
            startOffset = offset;
View Full Code Here

public class TestGzipReader_InputStreamReadSkip {

    @Test
    public void test_gzipreader() {
        InputStream in;
        ByteCountingPushBackInputStream pbin;
        GzipReader reader;

        out = new ByteArrayOutputStream();

        String fname = "IAH-20080430204825-00000-blackbook.warc.gz";

        try {
            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntries(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntryTotalTripleTrouble(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntryTotalTripleTrouble(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntryTotalTripleTroubleSkip(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntryTotalTripleTroubleSkip(reader);
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
View Full Code Here

public class TestGzipReader {

    @Test
    public void test_gzipreader_nextentry() {
        InputStream in;
        ByteCountingPushBackInputStream pbin;
        GzipReader reader;

        out = new ByteArrayOutputStream();

        String fname = "IAH-20080430204825-00000-blackbook.warc.gz";

        try {
            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader, Integer.MAX_VALUE);
            reader.close();
            pbin.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntries(reader, Integer.MAX_VALUE);
            reader.close();
            pbin.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader, 1);
            reader.close();
            pbin.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());

        } catch (IOException e) {
View Full Code Here

public class TestGzipReader_InputStreamSkippingClose {

    @Test
    public void test_gzipreader_inputstream_skippingclose() {
        InputStream in;
        ByteCountingPushBackInputStream pbin;
        GzipReader reader;

        String fname = "IAH-20080430204825-00000-blackbook.warc.gz";

        try {
            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntries(reader);
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
View Full Code Here

public class TestGzipReader_InputStream {

    @Test
    public void test_gzipreader() {
        InputStream in;
        ByteCountingPushBackInputStream pbin;
        GzipReader reader;

         String fname = "IAH-20080430204825-00000-blackbook.warc.gz";

        try {
            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntries(reader);
            pbin.close();

            in = this.getClass().getClassLoader().getResourceAsStream(fname);
            readEntriesOld(in);
        } catch (IOException e) {
            e.printStackTrace();
View Full Code Here

public class TestGzipReader_IsMagic {

    @Test
    public void test_magicbytes_old() {
        byte[] bytes;
        ByteCountingPushBackInputStream pbin;
        try {
            GzipInputStream.isGzipped(null);
            Assert.fail("Exception expected!");
        } catch (IllegalArgumentException e) {
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
        try {
            bytes = GzipConstants.GZIP_MAGIC_HEADER;
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertTrue(GzipInputStream.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x1f, (byte)0x8b, (byte)0x2f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertTrue(GzipInputStream.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x8b, (byte)0x1f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipInputStream.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x1f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipInputStream.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x8b};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipInputStream.isGzipped(pbin));
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
View Full Code Here

    }

    @Test
    public void test_magicbytes_new() {
        byte[] bytes;
        ByteCountingPushBackInputStream pbin;
        try {
            GzipReader.isGzipped(null);
            Assert.fail("Exception expected!");
        } catch (IllegalArgumentException e) {
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
        try {
            bytes = GzipConstants.GZIP_MAGIC_HEADER;
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertTrue(GzipReader.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x1f, (byte)0x8b, (byte)0x2f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertTrue(GzipReader.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x8b, (byte)0x1f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipReader.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x1f};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipReader.isGzipped(pbin));
            pbin.close();

            bytes = new byte[] {(byte)0x8b};
            pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), 16);
            Assert.assertFalse(GzipReader.isGzipped(pbin));
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
View Full Code Here

public class TestGzipWriter_Cloning {

    @Test
    public void test_gzipwriter_cloning() {
        InputStream in;
        ByteCountingPushBackInputStream pbin;
        GzipReader reader;
        GzipWriter writer = null;

        String in_file = "IAH-20080430204825-00000-blackbook.warc.gz";

        RandomAccessFile raf;
        RandomAccessFileOutputStream out;

        try {
            File out_file1 = File.createTempFile("jwat-testwrite3-", ".gz");
            File out_file2 = File.createTempFile("jwat-testwrite4-", ".gz");
            out_file1.deleteOnExit();
            out_file2.deleteOnExit();

            in = this.getClass().getClassLoader().getResourceAsStream(in_file);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);

            raf = new RandomAccessFile(out_file1, "rw");
            raf.seek(0);
            raf.setLength(0);
            out = new RandomAccessFileOutputStream(raf);
            writer = new GzipWriter(out);

            cloneEntries(reader, writer);
            pbin.close();

            out.flush();
            out.close();
            raf.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
            Assert.assertTrue(writer.isCompliant());
            Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());

            reader.close();
            writer.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
            Assert.assertTrue(writer.isCompliant());
            Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());

            in = this.getClass().getClassLoader().getResourceAsStream(in_file);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);

            raf = new RandomAccessFile(out_file2, "rw");
            raf.seek(0);
            raf.setLength(0);
            out = new RandomAccessFileOutputStream(raf);
            writer = new GzipWriter(out);

            cloneEntries(reader, writer);
            pbin.close();

            out.flush();
            out.close();
            raf.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
            Assert.assertTrue(writer.isCompliant());
            Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());

            reader.close();
            writer.close();

            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
            Assert.assertTrue(writer.isCompliant());
            Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());

            in = this.getClass().getClassLoader().getResourceAsStream(in_file);
            readEntriesOld(in);

            raf = new RandomAccessFile(out_file1, "rw");
            raf.seek(0);
            in = new RandomAccessFileInputStream(raf);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin);
            readEntries(reader);
            pbin.close();

            raf = new RandomAccessFile(out_file2, "rw");
            raf.seek(0);
            in = new RandomAccessFileInputStream(raf);
            pbin = new ByteCountingPushBackInputStream(in, 16);
            reader = new GzipReader(pbin, 8192);
            readEntries(reader);
            pbin.close();
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Exception not expected!");
        }
    }
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.