rpffileindex.java

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

JAVA
1,054
字号
            this.records.add(record);
            this.keyIndex.put(key, record);
        }

        private synchronized long createUniqueKey()
        {
            return ++this.uniqueKey;
        }

        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);
            }

            // Clear any existing records.
            this.records.clear();
            this.keyIndex.clear();

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

            //noinspection UnusedDeclaration
            int componentLength = buffer.getInt();
            int recordTableOffset = buffer.getInt();
            int numRecords = buffer.getInt();
            
            buffer.position(location + recordTableOffset);
            for (int i = 0; i < numRecords; i++)
            {
                long key = buffer.getLong();
                Record rec = newRecord(key);
                rec.load(buffer);
            }

            buffer.position(savePos);
        }

        java.nio.ByteBuffer save() throws IOException
        {
            List<Record> records = this.getRecords();
            int numRecords = records.size();

            int headerLength = 3 * Integer.SIZE / 8;
            int length = headerLength;
            for (Record rec : records)
            {
                length += (Long.SIZE + rec.getSizeInBits()) / 8;
            }

            java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(length);
            buffer.putInt(length); // component length
            buffer.putInt(headerLength); // record table offset
            buffer.putInt(numRecords); // num records
            for (Record rec : records)
            {
                buffer.putLong(rec.getKey());
                rec.save(buffer);
            }
            buffer.flip();
            return buffer;
        }
    }

    public static class Record
    {
        private final long key;

        public Record(long key)
        {
            this.key = key;
        }

        public final long getKey()
        {
            return this.key;
        }

        void load(java.nio.ByteBuffer buffer) throws IOException
        {
        }

        void save(java.nio.ByteBuffer buffer) throws IOException
        {
        }

        int getSizeInBits()
        {
            return 0;
        }
    }

    public static interface RecordFactory
    {
        Record newRecord(long key);
    }

    private static class DefaultRecordFactory implements RecordFactory
    {
        public Record newRecord(long key)
        {
            return new Record(key);
        }
    }

    public static class RPFFileRecord extends Record
    {
        private String filename;
        private long directorySecondaryKey = Table.INVALID_KEY;
        private long waveletSecondaryKey = Table.INVALID_KEY;
        private Angle minLatitude;
        private Angle maxLatitude;
        private Angle minLongitude;
        private Angle maxLongitude;
        private static int FILENAME_LENGTH = 12;
        private static int SIZE =
            (FILENAME_LENGTH * Byte.SIZE) // Filename.
            + Long.SIZE // Directory path secondary key.
            + Long.SIZE // Wavelet file secondary key.
            + (4 * Double.SIZE); // min-latitude, max-latitude, min-longitude, and max-longitude.

        public RPFFileRecord(long key)
        {
            super(key);
        }

        public String getFilename()
        {
            return this.filename;
        }

        public void setFilename(String filename)
        {
            this.filename = filename;
        }

        public long getDirectorySecondaryKey()
        {
            return this.directorySecondaryKey;
        }

        public long getWaveletSecondaryKey()
        {
            return this.waveletSecondaryKey;
        }

        public Sector getSector()
        {
            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 setSector(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) throws IOException
        {
            if (buffer == null)
            {
                String message = Logging.getMessage("nullValue.ByteBufferIsNull");
                Logging.logger().severe(message);
                throw new IllegalArgumentException(message);
            }

            this.filename = getString(buffer, FILENAME_LENGTH);
            this.directorySecondaryKey = buffer.getLong();
            this.waveletSecondaryKey = buffer.getLong();
            this.minLatitude = getAngle(buffer);
            this.maxLatitude = getAngle(buffer);
            this.minLongitude = getAngle(buffer);
            this.maxLongitude = getAngle(buffer);
        }

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

            putString(buffer, this.filename, FILENAME_LENGTH);
            buffer.putLong(this.directorySecondaryKey);
            buffer.putLong(this.waveletSecondaryKey);
            putAngle(buffer, this.minLatitude);
            putAngle(buffer, this.maxLatitude);
            putAngle(buffer, this.minLongitude);
            putAngle(buffer, this.maxLongitude);
        }

        int getSizeInBits()
        {
            return SIZE + super.getSizeInBits();
        }
    }

    public static class WaveletRecord extends Record
    {
        private String filename;
        private long directorySecondaryKey = Table.INVALID_KEY;
        private long rpfFileSecondaryKey = Table.INVALID_KEY;
        private static int FILENAME_LENGTH = 16;
        private static int SIZE =
            (FILENAME_LENGTH * Byte.SIZE) // Filename.
            + Long.SIZE // Directory path secondary key.
            + Long.SIZE; // RPF file secondary key.

        public WaveletRecord(long key)
        {
            super(key);
        }

        public String getFilename()
        {
            return this.filename;
        }

        public void setFilename(String filename)
        {
            this.filename = filename;
        }

        public long getDirectorySecondaryKey()
        {
            return this.directorySecondaryKey;
        }

        public long getRPFFileSecondaryKey()
        {
            return this.rpfFileSecondaryKey;
        }

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

            this.filename = getString(buffer, FILENAME_LENGTH);
            this.directorySecondaryKey = buffer.getLong();
            this.rpfFileSecondaryKey = buffer.getLong();
        }

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

            putString(buffer, this.filename, FILENAME_LENGTH);
            buffer.putLong(this.directorySecondaryKey);
            buffer.putLong(this.rpfFileSecondaryKey);
        }

        int getSizeInBits()
        {
            return SIZE + super.getSizeInBits();
        }
    }

    public static class DirectoryRecord extends Record
    {
        private String path;
        private static int PATH_LENGTH = 512;
        private static int SIZE =
            (PATH_LENGTH * Byte.SIZE); // Path.

        public DirectoryRecord(long key)
        {
            super(key);
        }

        public String getPath()
        {
            return this.path;
        }

        public void setPath(String path)
        {
            if (path == null)
            {
                String message = Logging.getMessage("nullValue.StringIsNull");
                Logging.logger().severe(message);
                throw new IllegalArgumentException(message);
            }

            this.path = path;
        }

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

            this.path = getString(buffer, PATH_LENGTH);
        }

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

            putString(buffer, this.path, PATH_LENGTH);
        }

        int getSizeInBits()
        {
            return SIZE + super.getSizeInBits();
        }
    }

    public static class IndexProperties
    {
        public String rootPath;
        public String dataSeriesIdentifier;
        public String description;
        public Angle minLatitude;
        public Angle maxLatitude;
        public Angle minLongitude;
        public Angle maxLongitude;

⌨️ 快捷键说明

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