rpffileindex.java

来自「world wind java sdk 源码」· Java 代码 · 共 1,054 行 · 第 1/3 页

JAVA
1,054
字号
        private static int ROOT_PATH_LENGTH = 512;
        private static int DATA_SERIES_ID_LENGTH = 512;
        private static int DESCRIPTION_LENGTH = 4096;
        private static int SIZE =
            Integer.SIZE // Section length.
            + (ROOT_PATH_LENGTH * Byte.SIZE) // Root path.
            + (DATA_SERIES_ID_LENGTH * Byte.SIZE) // Data series identifier.
            + (DESCRIPTION_LENGTH * Byte.SIZE) // Description.
            + (4 * Double.SIZE); // min-latitude, max-latitude, min-longitude, and max-longitude.

        public IndexProperties()
        {
        }

        public String getRootPath()
        {
            return this.rootPath;
        }

        public void setRootPath(String rootPath)
        {
            this.rootPath = rootPath;
        }

        public String getDataSeriesIdentifier()
        {
            return this.dataSeriesIdentifier;
        }

        public void setDataSeriesIdentifier(String dataSeriesIdentifier)
        {
            this.dataSeriesIdentifier = dataSeriesIdentifier;
        }

        public String getDescription()
        {
            return this.description;
        }

        public void setDescription(String description)
        {
            this.description = description;
        }

        public Sector getBoundingSector()
        {
            Sector sector = null;
            if (this.minLatitude != null
                && this.maxLatitude != null
                && this.minLongitude != null
                && this.maxLongitude != null)
            {
                sector = new Sector(
                    this.minLatitude, this.maxLatitude,
                    this.minLongitude, this.maxLongitude);
            }
            return sector;
        }

        public void setBoundingSector(Sector sector)
        {
            this.minLatitude = sector != null ? sector.getMinLatitude() : null;
            this.maxLatitude = sector != null ? sector.getMaxLatitude() : null;
            this.minLongitude = sector != null ? sector.getMinLongitude() : null;
            this.maxLongitude = sector != null ? sector.getMaxLongitude() : null;
        }

        void load(java.nio.ByteBuffer buffer, int location) throws IOException
        {
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.ByteBufferIsNull");
                Logging.logger().severe(message);
                throw new IllegalArgumentException(message);
            }

            int savePos = buffer.position();
            buffer.position(location);

            //noinspection UnusedDeclaration
            int length = buffer.getInt();
            this.rootPath = getString(buffer, ROOT_PATH_LENGTH);
            this.dataSeriesIdentifier = getString(buffer, DATA_SERIES_ID_LENGTH);
            this.description = getString(buffer, DESCRIPTION_LENGTH);
            this.minLatitude = getAngle(buffer);
            this.maxLatitude = getAngle(buffer);
            this.minLongitude = getAngle(buffer);
            this.maxLongitude = getAngle(buffer);

            buffer.position(savePos);
        }

        java.nio.ByteBuffer save() throws IOException
        {
            int length = SIZE / 8;
            java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(length);
            buffer.putInt(length);
            putString(buffer, this.rootPath, ROOT_PATH_LENGTH);
            putString(buffer, this.dataSeriesIdentifier, DATA_SERIES_ID_LENGTH);
            putString(buffer, this.description, DESCRIPTION_LENGTH);
            putAngle(buffer, this.minLatitude);
            putAngle(buffer, this.maxLatitude);
            putAngle(buffer, this.minLongitude);
            putAngle(buffer, this.maxLongitude);
            buffer.flip();
            return buffer;
        }
    }

    private static class LocationSection
    {
        public int locationSectionLength;
        public int componentLocationTableOffset;
        public int numOfComponentLocationRecords;

        private java.util.Map<Integer, ComponentLocationRecord> table =
            new java.util.HashMap<Integer, ComponentLocationRecord>();

        public LocationSection()
        {
            for (int i = 1; i <= 4; i++)
                this.table.put(i, new ComponentLocationRecord(i, -1, -1));
            this.locationSectionLength = (3 * Integer.SIZE / 8) + (this.table.size() * 3 * Integer.SIZE / 8);
            this.componentLocationTableOffset = (3 * Integer.SIZE / 8);
            this.numOfComponentLocationRecords = this.table.size();
        }

        public LocationSection(java.nio.ByteBuffer buffer) throws IOException
        {
            int savePos = buffer.position();

            this.locationSectionLength = buffer.getInt();
            this.componentLocationTableOffset = buffer.getInt();
            this.numOfComponentLocationRecords = buffer.getInt();

            buffer.position(savePos + this.componentLocationTableOffset);
            for (int i = 0; i < this.numOfComponentLocationRecords; i++)
            {
                int id = buffer.getInt();
                table.put(id, new ComponentLocationRecord(id,
                    buffer.getInt(), // length
                    buffer.getInt()  // location
                ));
            }

            buffer.position(savePos);
        }

        public java.nio.ByteBuffer save() throws IOException
        {
            java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(this.locationSectionLength);
            buffer.putInt(this.locationSectionLength);
            buffer.putInt(this.componentLocationTableOffset);
            buffer.putInt(this.numOfComponentLocationRecords);

            Collection<ComponentLocationRecord> records = table.values();
            ComponentLocationRecord[] recordArray = new ComponentLocationRecord[records.size()];
            records.toArray(recordArray);

            buffer.position(this.componentLocationTableOffset);
            for (int i = 0; i < this.numOfComponentLocationRecords; i++)
            {
                ComponentLocationRecord rec = recordArray[i];
                buffer.putInt(rec.getId());
                buffer.putInt(rec.getLength());
                buffer.putInt(rec.getLocation());
            }

            buffer.flip();
            return buffer;
        }

        public int getInformationSectionLocation()
        {
            return getLocation(1);
        }

        public int getInformationSectionLength()
        {
            return getLength(1);
        }

        public void setInformationSection(int length, int location)
        {
            set(1, length, location);
        }

        public int getRPFFileTableSectionLocation()
        {
            return getLocation(2);
        }

        public int getRPFFileTableSectionLength()
        {
            return getLength(2);
        }

        public void setRPFFileTableSection(int length, int location)
        {
            set(2, length, location);
        }

        public int getWaveletTableSectionLocation()
        {
            return getLocation(3);
        }

        public int getWaveletTableSectionLength()
        {
            return getLength(3);
        }

        public void setWaveletTableSection(int length, int location)
        {
            set(3, length, location);
        }

        public int getDirectoryTableSectionLocation()
        {
            return getLocation(4);
        }

        public int getDirectoryTableSectionLength()
        {
            return getLength(4);
        }

        public void setDirectoryTableSection(int length, int location)
        {
            set(4, length, location);
        }

        private int getLocation(int componentID)
        {
            ComponentLocationRecord rec = this.getRecord(componentID);
            return (null != rec) ? rec.getLocation() : 0;
        }

        private int getLength(int componentID)
        {
            ComponentLocationRecord rec = this.getRecord(componentID);
            return (null != rec) ? rec.getLength() : 0;
        }

        private void set(int componentID, int length, int location)
        {
            ComponentLocationRecord rec = this.getRecord(componentID);
            if (rec != null)
            {
                rec.length = length;
                rec.location = location;
            }
        }

        private ComponentLocationRecord getRecord(int componentID)
        {
            if(table.containsKey(componentID))
                return table.get(componentID);
            return null;
        }

        public static class ComponentLocationRecord
        {
            private int  id;
            private int length;
            private int location;

            public ComponentLocationRecord(int id, int length, int location)
            {
                this.id = id;
                this.length = length;
                this.location = location;
            }

            public int getId()
            {
                return id;
            }

            public int getLength()
            {
                return length;
            }

            public int getLocation()
            {
                return location;
            }
        }
    }

    private static final String CHARACTER_ENCODING = "UTF-8";

    private static String getString(java.nio.ByteBuffer buffer, int len) throws IOException
    {
        String s = null;
        if (buffer != null && buffer.remaining() >= len)
        {
            byte[] dest = new byte[len];
            buffer.get(dest, 0, len);
            s = new String(dest, CHARACTER_ENCODING).trim();
        }
        return s;
    }

    private static void putString(java.nio.ByteBuffer buffer, String s, int len) throws IOException
    {
        if (buffer != null)
        {
            byte[] src = new byte[len];
            if (s != null)
            {
                byte[] utfBytes = s.getBytes(CHARACTER_ENCODING);
                if (utfBytes != null)
                {
                    System.arraycopy(utfBytes, 0, src, 0, utfBytes.length);
                }
            }
            buffer.put(src, 0, len);
        }
    }

    private static Angle getAngle(java.nio.ByteBuffer buffer)
    {
        // The binary description of an angle needs to distinguish between
        // non-null and null. We use Double.NaN as a marker for a null-value.
        Angle a = null;
        if (buffer != null)
        {
            double value = buffer.getDouble();
            if (!Double.isNaN(value))
            {
                a = Angle.fromDegrees(value);
            }
        }
        return a;
    }

    private static void putAngle(java.nio.ByteBuffer buffer, Angle angle)
    {
        // The binary description of an angle needs to distinguish between
        // non-null and null. We use Double.NaN as a marker for a null-value.
        if (buffer != null)
        {
            double value = angle != null ? angle.degrees : Double.NaN;
            buffer.putDouble(value);
        }
    }
}

⌨️ 快捷键说明

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