Package org.jwat.common

Examples of org.jwat.common.RandomAccessFileOutputStream


            raf = new RandomAccessFile(out_file, "rw");
            raf.seek(0);
            raf.setLength(0);
            //OutputStream out = new FileOutputStream( "WarcWriteTest.warc" );
            OutputStream out = new RandomAccessFileOutputStream( raf );

            reader = WarcReaderFactory.getReader( in );

            if (bBuffer) {
                writer = WarcWriterFactory.getWriter(out, 8192, bCompress);
            } else {
                writer = WarcWriterFactory.getWriter(out, bCompress);
            }

            //System.out.println(writer);

            records = 0;
            errors = 0;
            warnings = 0;

            while ( (record = reader.getNextRecord()) != null ) {
                if (bDebugOutput) {
                    TestBaseUtils.printRecord(record);
                    TestBaseUtils.printRecordErrors(record);
                }

                ++records;

                if (record.diagnostics.hasErrors()) {
                    errors += record.diagnostics.getErrors().size();
                }
                if (record.diagnostics.hasWarnings()) {
                    warnings += record.diagnostics.getWarnings().size();
                }

                writer.writeHeader(record);

                if ( record.hasPayload() ) {
                    Payload payload = record.getPayload();
                    //writer.transfer( payload.getInputStream(), payload.getTotalLength() );
                    writer.streamPayload( payload.getInputStreamComplete() );
                }

                writer.closeRecord();
            }

            if (bDebugOutput) {
                System.out.println("--------------");
                System.out.println("       Records: " + records);
                System.out.println("        Errors: " + errors);
            }

            reader.close();
            in.close();
            writer.close();
            out.close();

            Assert.assertEquals(expected_records, records);
            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(0, errors);
            Assert.assertEquals(0, warnings);
            Assert.assertEquals(11231015, reader.getConsumed());

            /*
             * Validate written warc.
             */

            raf.seek(0);
            in = new RandomAccessFileInputStream( raf );

            reader = WarcReaderFactory.getReader( in );

            //System.out.println(reader);

            records = 0;
            errors = 0;
            warnings = 0;

            while ( (record = reader.getNextRecord()) != null ) {
                if (bDebugOutput) {
                    TestBaseUtils.printRecord(record);
                    TestBaseUtils.printRecordErrors(record);
                }

                ++records;

                if (record.diagnostics.hasErrors()) {
                    errors += record.diagnostics.getErrors().size();
                }
                if (record.diagnostics.hasWarnings()) {
                    warnings += record.diagnostics.getWarnings().size();
                }
            }

            if (bDebugOutput) {
                System.out.println("--------------");
                System.out.println("       Records: " + records);
                System.out.println("        Errors: " + errors);
            }

            reader.close();
            in.close();
            writer.close();
            out.close();

            Assert.assertEquals(expected_records, records);
            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(0, errors);
            Assert.assertEquals(0, warnings);
View Full Code Here


            raf = new RandomAccessFile(out_file, "rw");
            raf.seek(0);
            raf.setLength(0);
            //OutputStream out = new FileOutputStream( "WarcWriteTest.warc" );
            OutputStream out = new RandomAccessFileOutputStream( raf );

            reader = WarcReaderFactory.getReader( in );

            if (bBuffer) {
                writer = WarcWriterFactory.getWriter(out, 8192, bCompress);
            } else {
                writer = WarcWriterFactory.getWriter(out, bCompress);
            }

            //System.out.println(writer);

            records = 0;
            errors = 0;
            warnings = 0;

            while ( (record = reader.getNextRecord()) != null ) {
                if (bDebugOutput) {
                    TestBaseUtils.printRecord(record);
                    TestBaseUtils.printRecordErrors(record);
                }

                ++records;

                if (record.diagnostics.hasErrors()) {
                    errors += record.diagnostics.getErrors().size();
                }
                if (record.diagnostics.hasWarnings()) {
                    warnings += record.diagnostics.getWarnings().size();
                }

                writer.writeRawHeader(record.header.headerBytes, record.header.contentLength);

                if ( record.hasPayload() ) {
                    Payload payload = record.getPayload();
                    //writer.transfer( payload.getInputStream(), payload.getTotalLength() );
                    writer.streamPayload( payload.getInputStreamComplete() );
                }

                writer.closeRecord();
            }

            if (bDebugOutput) {
                System.out.println("--------------");
                System.out.println("       Records: " + records);
                System.out.println("        Errors: " + errors);
            }

            reader.close();
            in.close();
            writer.close();
            out.close();

            Assert.assertEquals(expected_records, records);
            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(0, errors);
            Assert.assertEquals(0, warnings);
            Assert.assertEquals(11231015, reader.getConsumed());

            /*
             * Validate written warc.
             */

            raf.seek(0);
            in = new RandomAccessFileInputStream( raf );

            reader = WarcReaderFactory.getReader( in );

            //System.out.println(reader);

            records = 0;
            errors = 0;
            warnings = 0;

            while ( (record = reader.getNextRecord()) != null ) {
                if (bDebugOutput) {
                    TestBaseUtils.printRecord(record);
                    TestBaseUtils.printRecordErrors(record);
                }

                ++records;

                if (record.diagnostics.hasErrors()) {
                    errors += record.diagnostics.getErrors().size();
                }
                if (record.diagnostics.hasWarnings()) {
                    warnings += record.diagnostics.getWarnings().size();
                }
            }

            if (bDebugOutput) {
                System.out.println("--------------");
                System.out.println("       Records: " + records);
                System.out.println("        Errors: " + errors);
            }

            reader.close();
            in.close();
            writer.close();
            out.close();

            Assert.assertEquals(expected_records, records);
            Assert.assertTrue(reader.isCompliant());
            Assert.assertEquals(0, errors);
            Assert.assertEquals(0, warnings);
View Full Code Here

        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());
View Full Code Here

TOP

Related Classes of org.jwat.common.RandomAccessFileOutputStream

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.