Package org.jwat.common

Examples of org.jwat.common.Diagnosis


            }
            int read;
            try {
                read = reader.readInflated(b, off, len);
            } catch (DataFormatException e) {
                gzipEntry.diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_DATA, "GZip file", "Unexpected EOF!"));
                reader.bIsCompliant = false;
                throw new IOException(e);
            }
            if (read != -1) {
                reader.crc.update(b, off, read);
View Full Code Here


        ArcWriter writer;
        ArcRecordBase record;
        byte[] recordHeader;
        ByteArrayInputStream in;
        byte[] payload;
        Diagnosis diagnosis;
        try {
            payload = "Welcome to dænemark!".getBytes("UTF-8");

            /*
             * Exceptions enabled.
View Full Code Here

        TestBaseUtils.compareDiagnoses(expected_errors, header.diagnostics.getErrors());
        TestBaseUtils.compareDiagnoses(expected_warnings, header.diagnostics.getWarnings());
    }

    public static void compareDiagnoses(Object[][] expectedDiagnoses, List<Diagnosis> diagnosisList) {
        Diagnosis diagnosis;
        // debug
        /*
        System.out.println(diagnosisList.size());
        for (int i=0; i<diagnosisList.size(); ++i) {
            diagnosis = diagnosisList.get(i);
View Full Code Here

    }

    public static void printRecordErrors(ArcRecordBase record) {
        List<Diagnosis> diagnosisList;
        Iterator<Diagnosis> diagnosisIterator;
        Diagnosis diagnosis;
        if (record.diagnostics.hasErrors()) {
            diagnosisList = record.diagnostics.getErrors();
            if (diagnosisList != null && diagnosisList.size() > 0) {
                diagnosisIterator = diagnosisList.iterator();
                while (diagnosisIterator.hasNext()) {
View Full Code Here

            if (header != null) {
                diagnosticsUsed = header.diagnostics;
            } else {
                diagnosticsUsed = diagnostics;
            }
            diagnosticsUsed.addError(new Diagnosis(
                    DiagnosisType.ERROR_EXPECTED,
                    "'" + ArcConstants.FN_ARCHIVE_LENGTH + "' header",
                    "Mandatory!"));
            if (bExceptionOnContentLengthMismatch) {
                throw new IllegalStateException("Payload size does not match content-length!");
            }
        } else {
            if (headerContentLength != payloadWrittenTotal) {
                if (header != null) {
                    diagnosticsUsed = header.diagnostics;
                } else {
                    diagnosticsUsed = diagnostics;
                }
                diagnosticsUsed.addError(new Diagnosis(
                        DiagnosisType.INVALID_EXPECTED,
                        "'" + ArcConstants.FN_ARCHIVE_LENGTH + "' header",
                        Long.toString(payloadWrittenTotal),
                        headerContentLength.toString()));
                if (bExceptionOnContentLengthMismatch) {
View Full Code Here

    private TestBaseUtils() {
    }

    public static void compareDiagnoses(Object[][] expectedDiagnoses, List<Diagnosis> diagnosisList) {
        Diagnosis diagnosis;
        // debug
        /*
        System.out.println(diagnosisList.size());
        for (int i=0; i<diagnosisList.size(); ++i) {
            diagnosis = diagnosisList.get(i);
View Full Code Here

            Assert.assertEquals(expectedDiagnoses[i][2], diagnosis.information.length);
        }
    }

    public static void printDiagnoses(List<Diagnosis> diagnosisList) {
        Diagnosis diagnosis;
        for (int i=0; i<diagnosisList.size(); ++i) {
            diagnosis = diagnosisList.get(i);
            System.out.println("[" + i + "]: " + diagnosis.type + " - " + diagnosis.entity + " - " + diagnosis.information.length);
        }
    }
View Full Code Here

    }

    public static void printRecordErrors(WarcRecord record) {
        List<Diagnosis> diagnosisList;
        Iterator<Diagnosis> diagnosisIterator;
        Diagnosis diagnosis;
        if (record.diagnostics.hasErrors()) {
            diagnosisList = record.diagnostics.getErrors();
            if (diagnosisList != null && diagnosisList.size() > 0) {
                diagnosisIterator = diagnosisList.iterator();
                while (diagnosisIterator.hasNext()) {
View Full Code Here

            entry.xfl |= GzipConstants.DEFLATE_XFL_MAXIMUM_COMPRESSION;
        }
        entry.flg = 0;
        if (!GzipConstants.osIdxStr.containsKey((int)entry.os)) {
            entry.diagnostics.addWarning(
                    new Diagnosis(
                            DiagnosisType.UNKNOWN,
                            "Operating System",
                            Integer.toString(entry.os)
                )
            );
        }
        /*
         * FTEXT.
         */
        if (entry.bFText) {
            entry.flg |= GzipConstants.FLG_FTEXT;
        }
        /*
         * FEXTRA.
         */
        if (entry.extraBytes == null) {
            if (entry.extraData.size() > 0) {
                int xlen = 0;
                for (int i=0; i<entry.extraData.size(); ++i) {
                    xlen += 4 + entry.extraData.get(i).data.length;
                }
                entry.extraBytes = new byte[xlen];
                GzipExtraData extraData;
                int idx = 0;
                for (int i=0; i<entry.extraData.size(); ++i) {
                    extraData = entry.extraData.get(i);
                    entry.extraBytes[idx++] = extraData.si1;
                    entry.extraBytes[idx++] = extraData.si2;
                    entry.extraBytes[idx++] = (byte)(extraData.data.length & 255);
                    entry.extraBytes[idx++] = (byte)((extraData.data.length >> 8) & 255);
                    System.arraycopy(extraData.data, 0, entry.extraBytes, idx, extraData.data.length);
                    idx += extraData.data.length;
                }
            }
        } else {
            int idx = 0;
            boolean b = true;
            int len;
            while (b) {
                if (idx <= entry.extraBytes.length - 4) {
                    idx += 2;
                    len = ((entry.extraBytes[idx + 1] & 255) << 8) | (entry.extraBytes[idx] & 255);
                    idx += 2;
                    if (idx + len <= entry.extraBytes.length) {
                        idx += len;
                    } else {
                        b = false;
                    }
                } else {
                    b = false;
                }
            }
            if (idx != gzipEntry.extraBytes.length) {
                gzipEntry.diagnostics.addError(
                        new Diagnosis(
                                DiagnosisType.INVALID_DATA,
                                "FEXTRA",
                                "Invalid structure",
                                "Data truncated"
                            )
                        );
            }
        }
        if (entry.extraBytes != null) {
            entry.flg |= GzipConstants.FLG_FEXTRA;
            entry.xlen = entry.extraBytes.length;
            xlenBytes[0] = (byte)(entry.xlen & 255);
            xlenBytes[1] = (byte)((entry.xlen >> 8) & 255);
        }
        /*
         * FNAME.
         */
        if (entry.fname != null) {
            entry.flg |= GzipConstants.FLG_FNAME;
            if (!iso8859_1.encode(entry.fname, "")) {
                entry.diagnostics.addWarning(
                        new Diagnosis(
                                DiagnosisType.INVALID_ENCODING,
                                "FName",
                                entry.fname,
                                "ISO-8859-1"
                            )
                        );
            }
            entry.fname = iso8859_1.decoded;
            fnameBytes = iso8859_1.encoded;
        }
        /*
         * FCOMMENT.
         */
        if (entry.fcomment != null) {
            entry.flg |= GzipConstants.FLG_FCOMMENT;
            if (!iso8859_1.encode(entry.fcomment, "\n")) {
                entry.diagnostics.addWarning(
                        new Diagnosis(
                                DiagnosisType.INVALID_ENCODING,
                                "FComment",
                                entry.fcomment,
                                "ISO-8859-1"
                            )
View Full Code Here

    }

    @Test
    public void test_empty_arcfile() {
        ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
        Diagnosis d;
        try {
            ArcReader reader = ArcReaderFactory.getReaderUncompressed(in);
            ArcRecordBase record = reader.getNextRecord();
            Assert.assertNull(record);
            Assert.assertFalse(reader.isCompliant());
View Full Code Here

TOP

Related Classes of org.jwat.common.Diagnosis

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.