Examples of Diagnosis


Examples of org.jwat.common.Diagnosis

            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

Examples of org.jwat.common.Diagnosis

    }

    @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

Examples of org.jwat.common.Diagnosis

            else {
                bSeekRecord = false;
            }
        }
        if (bInvalidDataBeforeVersion) {
            diagnostics.addError(new Diagnosis(DiagnosisType.INVALID, "Data before ARC record"));
        }
        if (bEmptyLinesBeforeVersion) {
            diagnostics.addError(new Diagnosis(DiagnosisType.INVALID, "Empty lines before ARC record"));
        }
        return bHeaderParsed;
    }
View Full Code Here

Examples of org.jwat.common.Diagnosis

                    resultCodeStr = null;
                }
                resultCode = fieldParsers.parseInteger(
                        resultCodeStr, ArcConstants.FN_RESULT_CODE, false);
                if (resultCode != null && (resultCode < 100 || resultCode > 999)) {
                    diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_EXPECTED,
                            "'" + ArcConstants.FN_RESULT_CODE + "' value",
                            resultCodeStr,
                            "A number between 100 and 999"));
                }

                checksumStr = fields[ArcConstants.FN_IDX_CHECKSUM];
                if ("-".equals(checksumStr)) {
                    checksumStr = null;
                }
                checksumStr = fieldParsers.parseString(
                        checksumStr, ArcConstants.FN_CHECKSUM, true);

                locationStr = fields[ArcConstants.FN_IDX_LOCATION];
                if ("-".equals(locationStr)) {
                    locationStr = null;
                }
                locationStr = fieldParsers.parseString(
                        locationStr, ArcConstants.FN_LOCATION, true);

                offsetStr = fields[ArcConstants.FN_IDX_OFFSET];
                if ("-".equals(offsetStr)) {
                    offsetStr = null;
                }
                offset = fieldParsers.parseLong(
                        offsetStr, ArcConstants.FN_OFFSET, false);
                if (offset != null && offset < 0) {
                    diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_EXPECTED,
                            "'" + ArcConstants.FN_OFFSET + "' value",
                            offsetStr,
                            "A non negative number"));
                }

                filenameStr = fields[ArcConstants.FN_IDX_FILENAME];
                if ("-".equals(filenameStr)) {
                    filenameStr = null;
                }
                filenameStr = reader.fieldParsers.parseString(
                        filenameStr, ArcConstants.FN_FILENAME, false);
            }
            archiveLengthStr = fields[fields.length - 1];
            if ("-".equals(archiveLengthStr)) {
                archiveLengthStr = null;
            }
            archiveLength = reader.fieldParsers.parseLong(
                    archiveLengthStr, ArcConstants.FN_ARCHIVE_LENGTH, false);
            if (archiveLength != null && archiveLength < 0) {
                diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_EXPECTED,
                        "'" + ArcConstants.FN_ARCHIVE_LENGTH + "' value",
                        archiveLengthStr,
                        "A non negative number"));
            }
        }
View Full Code Here

Examples of org.jwat.common.Diagnosis

    }

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

Examples of org.jwat.common.Diagnosis

     * more details and/or format information.
     * @param entity entity examined
     * @param information optional extra information
     */
    protected void addInvalidExpectedError(String entity, String... information) {
        diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_EXPECTED, entity, information));
    }
View Full Code Here

Examples of org.jwat.common.Diagnosis

     * Add an error diagnosis on the given entity stating that it is required
     * but is missing.
     * @param entity entity examined
     */
    protected void addRequiredMissingError(String entity) {
        diagnostics.addError(new Diagnosis(DiagnosisType.REQUIRED_MISSING, entity));
    }
View Full Code Here

Examples of org.jwat.common.Diagnosis

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

            /*
             * Exceptions enabled.
View Full Code Here

Examples of org.jwat.common.Diagnosis

     * more details and/or format information.
     * @param entity entity examined
     * @param information optional extra information
     */
    protected void addInvalidExpectedError(String entity, String... information) {
        diagnostics.addError(new Diagnosis(DiagnosisType.INVALID_EXPECTED, entity, information));
    }
View Full Code Here

Examples of org.jwat.common.Diagnosis

    /**
     * Add a warning diagnosis on the given entity stating that it is empty.
     * @param entity entity examined
     */
    protected void addEmptyWarning(String entity) {
        diagnostics.addWarning(new Diagnosis(DiagnosisType.EMPTY, entity));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.