⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddfrecord.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         * them.         */        /* -------------------------------------------------------------------- */        int i;        int nFieldEntryWidth;        nFieldEntryWidth = _sizeFieldLength + _sizeFieldPos + _sizeFieldTag;        nFieldCount = 0;        for (i = 0; i < nDataSize; i += nFieldEntryWidth) {            if (pachData[i] == DDF_FIELD_TERMINATOR)                break;            nFieldCount++;        }        /* ==================================================================== */        /* Allocate, and read field definitions. */        /* ==================================================================== */        paoFields = new Vector(nFieldCount);        for (i = 0; i < nFieldCount; i++) {            String szTag;            int nEntryOffset = i * nFieldEntryWidth;            int nFieldLength, nFieldPos;            /* -------------------------------------------------------------------- */            /* Read the position information and tag. */            /* -------------------------------------------------------------------- */            szTag = new String(pachData, nEntryOffset, _sizeFieldTag);            nEntryOffset += _sizeFieldTag;            nFieldLength = Integer.valueOf(new String(pachData, nEntryOffset, _sizeFieldLength))                    .intValue();            nEntryOffset += _sizeFieldLength;            nFieldPos = Integer.valueOf(new String(pachData, nEntryOffset, _sizeFieldPos))                    .intValue();            /* -------------------------------------------------------------------- */            /* Find the corresponding field in the module directory. */            /* -------------------------------------------------------------------- */            DDFFieldDefinition poFieldDefn = poModule.findFieldDefn(szTag);            if (poFieldDefn == null) {                Debug.error("DDFRecord: Undefined field " + szTag                        + " encountered in data record.");                return false;            }            DDFField ddff = null;            if (readSubfields) {                /* -------------------------------------------------------------------- */                /* Assign info the DDFField. */                /* -------------------------------------------------------------------- */                byte[] tempData = new byte[nFieldLength];                System.arraycopy(pachData, _fieldAreaStart + nFieldPos                        - DDF_LEADER_SIZE, tempData, 0, tempData.length);                ddff = new DDFField(poFieldDefn, tempData, readSubfields);            } else {                // Save the info for reading later directly out of the                // field.                ddff = new DDFField(poFieldDefn, nFieldPos, nFieldLength);                ddff.setHeaderOffset(poModule._recLength + _fieldAreaStart);            }            paoFields.add(ddff);        }        return true;    }    /**     * Find the named field within this record.     *      * @param pszName The name of the field to fetch. The comparison     *        is case insensitive.     * @param iFieldIndex The instance of this field to fetch. Use     *        zero (the default) for the first instance.     *      * @return Pointer to the requested DDFField. This pointer is to     *         an internal object, and should not be freed. It remains     *         valid until the next record read.     */    public DDFField findField(String pszName, int iFieldIndex) {        for (Iterator it = paoFields.iterator(); it.hasNext();) {            DDFField ddff = (DDFField) it.next();            if (pszName.equalsIgnoreCase(ddff.getFieldDefn().getName())) {                if (iFieldIndex == 0) {                    return ddff;                } else {                    iFieldIndex--;                }            }        }        return null;    }    /**     * Fetch field object based on index.     *      * @param i The index of the field to fetch. Between 0 and     *        GetFieldCount()-1.     *      * @return A DDFField pointer, or null if the index is out of     *         range.     */    public DDFField getField(int i) {        try {            return (DDFField) paoFields.elementAt(i);        } catch (ArrayIndexOutOfBoundsException aioobe) {            return null;        }    }    /**     * Get an interator over the fields.     */    public Iterator iterator() {        if (paoFields != null) {            return paoFields.iterator();        }        return null;    }    /**     * Fetch value of a subfield as an integer. This is a convenience     * function for fetching a subfield of a field within this record.     *      * @param pszField The name of the field containing the subfield.     * @param iFieldIndex The instance of this field within the     *        record. Use zero for the first instance of this field.     * @param pszSubfield The name of the subfield within the selected     *        field.     * @param iSubfieldIndex The instance of this subfield within the     *        record. Use zero for the first instance.     * @return The value of the subfield, or zero if it failed for     *         some reason.     */    public int getIntSubfield(String pszField, int iFieldIndex,                              String pszSubfield, int iSubfieldIndex) {        DDFField poField;        /* -------------------------------------------------------------------- */        /* Fetch the field. If this fails, return zero. */        /* -------------------------------------------------------------------- */        poField = findField(pszField, iFieldIndex);        if (poField == null) {            return 0;        }        /* -------------------------------------------------------------------- */        /* Get the subfield definition */        /* -------------------------------------------------------------------- */        DDFSubfieldDefinition poSFDefn = poField.getFieldDefn()                .findSubfieldDefn(pszSubfield);        if (poSFDefn == null) {            return 0;        }        /* -------------------------------------------------------------------- */        /* Get a pointer to the data. */        /* -------------------------------------------------------------------- */        MutableInt nBytesRemaining = new MutableInt();        byte[] pachData = poField.getSubfieldData(poSFDefn,                nBytesRemaining,                iSubfieldIndex);        /* -------------------------------------------------------------------- */        /* Return the extracted value. */        /* -------------------------------------------------------------------- */        return poSFDefn.extractIntData(pachData, nBytesRemaining.value, null);    }    /**     * Fetch value of a subfield as a float (double). This is a     * convenience function for fetching a subfield of a field within     * this record.     *      * @param pszField The name of the field containing the subfield.     * @param iFieldIndex The instance of this field within the     *        record. Use zero for the first instance of this field.     * @param pszSubfield The name of the subfield within the selected     *        field.     * @param iSubfieldIndex The instance of this subfield within the     *        record. Use zero for the first instance.     * @return The value of the subfield, or zero if it failed for     *         some reason.     */    public double getFloatSubfield(String pszField, int iFieldIndex,                                   String pszSubfield, int iSubfieldIndex) {        DDFField poField;        /* -------------------------------------------------------------------- */        /* Fetch the field. If this fails, return zero. */        /* -------------------------------------------------------------------- */        poField = findField(pszField, iFieldIndex);        if (poField == null) {            return 0;        }        /* -------------------------------------------------------------------- */        /* Get the subfield definition */        /* -------------------------------------------------------------------- */        DDFSubfieldDefinition poSFDefn = poField.getFieldDefn()                .findSubfieldDefn(pszSubfield);        if (poSFDefn == null) {            return 0;        }        /* -------------------------------------------------------------------- */        /* Get a pointer to the data. */        /* -------------------------------------------------------------------- */        MutableInt nBytesRemaining = new MutableInt();        byte[] pachData = poField.getSubfieldData(poSFDefn,                nBytesRemaining,                iSubfieldIndex);        /* -------------------------------------------------------------------- */        /* Return the extracted value. */        /* -------------------------------------------------------------------- */        return poSFDefn.extractFloatData(pachData, nBytesRemaining.value, null);    }    /**     * Fetch value of a subfield as a string. This is a convenience     * function for fetching a subfield of a field within this record.     *      * @param pszField The name of the field containing the subfield.     * @param iFieldIndex The instance of this field within the     *        record. Use zero for the first instance of this field.     * @param pszSubfield The name of the subfield within the selected     *        field.     * @param iSubfieldIndex The instance of this subfield within the     *        record. Use zero for the first instance.     * @return The value of the subfield, or null if it failed for     *         some reason. The returned pointer is to internal data     *         and should not be modified or freed by the application.     */    String getStringSubfield(String pszField, int iFieldIndex,                             String pszSubfield, int iSubfieldIndex) {        DDFField poField;        /* -------------------------------------------------------------------- */        /* Fetch the field. If this fails, return zero. */        /* -------------------------------------------------------------------- */        poField = findField(pszField, iFieldIndex);        if (poField == null) {            return null;        }        /* -------------------------------------------------------------------- */        /* Get the subfield definition */        /* -------------------------------------------------------------------- */        DDFSubfieldDefinition poSFDefn = poField.getFieldDefn()                .findSubfieldDefn(pszSubfield);        if (poSFDefn == null) {            return null;        }        /* -------------------------------------------------------------------- */        /* Get a pointer to the data. */        /* -------------------------------------------------------------------- */        MutableInt nBytesRemaining = new MutableInt();        byte[] pachData = poField.getSubfieldData(poSFDefn,                nBytesRemaining,                iSubfieldIndex);        /* -------------------------------------------------------------------- */        /* Return the extracted value. */        /* -------------------------------------------------------------------- */        return poSFDefn.extractStringData(pachData, nBytesRemaining.value, null);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -