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

📄 ddffield.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ******************************************************************************/package com.bbn.openmap.dataAccess.iso8211;import com.bbn.openmap.layer.vpf.MutableInt;import com.bbn.openmap.util.Debug;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Vector;/** * This object represents one field in a DDFRecord. This models an * instance of the fields data, rather than it's data definition which * is handled by the DDFFieldDefn class. Note that a DDFField doesn't * have DDFSubfield children as you would expect. To extract subfield * values use GetSubfieldData() to find the right data pointer and * then use ExtractIntData(), ExtractFloatData() or * ExtractStringData(). */public class DDFField {    protected DDFFieldDefinition poDefn;    protected byte[] pachData;    protected Hashtable subfields;    protected int dataPosition;    protected int dataLength;    protected int headerOffset;    public DDFField() {}    public DDFField(DDFFieldDefinition poDefnIn, int dataPositionIn,            int dataLengthIn) {        initialize(poDefnIn, null);        dataPosition = dataPositionIn;        dataLength = dataLengthIn;    }    public DDFField(DDFFieldDefinition poDefnIn, byte[] pachDataIn) {        this(poDefnIn, pachDataIn, true);    }    public DDFField(DDFFieldDefinition poDefnIn, byte[] pachDataIn,            boolean doSubfields) {        initialize(poDefnIn, pachDataIn);        if (doSubfields) {            buildSubfields();        }    }    public void initialize(DDFFieldDefinition poDefnIn, byte[] pachDataIn) {        pachData = pachDataIn;        poDefn = poDefnIn;        subfields = new Hashtable();    }    /**     * Set how many bytes to add to the data position for absolute     * position in the data file for the field data.     */    protected void setHeaderOffset(int headerOffsetIn) {        headerOffset = headerOffsetIn;    }    /**     * Get how many bytes to add to the data position for absolute     * position in the data file for the field data.     */    public int getHeaderOffset() {        return headerOffset;    }    /**     * Return the pointer to the entire data block for this record.     * This is an internal copy, and shouldn't be freed by the     * application. If null, then check the dataPosition and     * daataLength for byte offsets for the data in the file, and go     * get it yourself. This is done for really large files where it     * doesn't make sense to load the data.     */    public byte[] getData() {        return pachData;    }    /**     * Return the number of bytes in the data block returned by     * GetData().     */    public int getDataSize() {        if (pachData != null) {            return pachData.length;        } else            return 0;    }    /** Fetch the corresponding DDFFieldDefn. */    public DDFFieldDefinition getFieldDefn() {        return poDefn;    }    /**     * If getData() returns null, it'll be your responsibilty to go     * after the data you need for this field.     *      * @return the byte offset into the source file to start reading     *         this field.     */    public int getDataPosition() {        return dataPosition;    }    /**     * If getData() returns null, it'll be your responsibilty to go     * after the data you need for this field.     *      * @return the number of bytes contained in the source file for     *         this field.     */    public int getDataLength() {        return dataLength;    }    /**     * Creates a string with variety of information about this field,     * and all it's subfields is written to the given debugging file     * handle. Note that field definition information (ala     * DDFFieldDefn) isn't written.     *      * @return String containing info.     */    public String toString() {        StringBuffer buf = new StringBuffer("  DDFField:\n");        buf.append("\tTag = " + poDefn.getName() + "\n");        buf.append("\tDescription = " + poDefn.getDescription() + "\n");        int size = getDataSize();        buf.append("\tDataSize = " + size + "\n");        if (pachData == null) {            buf.append("\tHeader offset = " + headerOffset + "\n");            buf.append("\tData position = " + dataPosition + "\n");            buf.append("\tData length = " + dataLength + "\n");            return buf.toString();        }        buf.append("\tData = ");        for (int i = 0; i < Math.min(size, 40); i++) {            if (pachData[i] < 32 || pachData[i] > 126) {                buf.append(" | " + (char) pachData[i]);            } else {                buf.append(pachData[i]);            }        }        if (size > 40)            buf.append("...");        buf.append("\n");        /* -------------------------------------------------------------------- */        /* dump the data of the subfields. */        /* -------------------------------------------------------------------- */        if (Debug.debugging("iso8211.raw")) {            int iOffset = 0;            MutableInt nBytesConsumed = new MutableInt(0);            for (int nLoopCount = 0; nLoopCount < getRepeatCount(); nLoopCount++) {                if (nLoopCount > 8) {                    buf.append("      ...\n");                    break;                }                for (int i = 0; i < poDefn.getSubfieldCount(); i++) {                    byte[] subPachData = new byte[pachData.length - iOffset];                    System.arraycopy(pachData,                            iOffset,                            subPachData,                            0,                            subPachData.length);                    buf.append(poDefn.getSubfieldDefn(i).dumpData(subPachData,                            subPachData.length));                    poDefn.getSubfieldDefn(i).getDataLength(subPachData,                            subPachData.length,                            nBytesConsumed);                    iOffset += nBytesConsumed.value;                }            }        } else {            buf.append("      Subfields:\n");            for (Enumeration enumeration = subfields.keys(); enumeration.hasMoreElements();) {                Object obj = subfields.get(enumeration.nextElement());                if (obj instanceof List) {                    for (Iterator it = ((List) obj).iterator(); it.hasNext();) {                        DDFSubfield ddfs = (DDFSubfield) it.next();                        buf.append("        " + ddfs.toString() + "\n");                    }                } else {                    buf.append("        " + obj.toString() + "\n");                }            }        }        return buf.toString();    }    /**     * Will return an ordered list of DDFSubfield objects. If the

⌨️ 快捷键说明

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