bytegetter.java

来自「postGIS是一个能够使用postSQL数据库来管理GIS数据的小程序,充分发」· Java 代码 · 共 75 行

JAVA
75
字号
/* * ByteGetter.java *  * PostGIS extension for PostgreSQL JDBC driver - Binary Parser *  * (C) 2005 Markus Schaber, markus.schaber@logix-tt.com *  * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 2.1 of the License. *  * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. *  * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at * http://www.gnu.org. *  * $Id: ByteGetter.java 1622 2005-04-15 14:04:34Z mschaber $ */package org.postgis.binary;public abstract class ByteGetter {    /**     * Get a byte.     *      * @return The result is returned as Int to eliminate sign problems when     *         or'ing several values together.     */    public abstract int get(int index);    public static class BinaryByteGetter extends ByteGetter {        private byte[] array;        public BinaryByteGetter(byte[] array) {            this.array = array;        }        public int get(int index) {            return array[index] & 0xFF; // mask out sign-extended bits.        }    }    public static class StringByteGetter extends ByteGetter {        private String rep;        public StringByteGetter(String rep) {            this.rep = rep;        }        public int get(int index) {            index *= 2;            int high = unhex(rep.charAt(index));            int low = unhex(rep.charAt(index + 1));            return (high << 4) + low;        }        public static byte unhex(char c) {            if (c >= '0' && c <= '9') {                return (byte) (c - '0');            } else if (c >= 'A' && c <= 'F') {                return (byte) (c - 'A' + 10);            } else if (c >= 'a' && c <= 'f') {                return (byte) (c - 'a' + 10);            } else {                throw new IllegalArgumentException("No valid Hex char " + c);            }        }    }}

⌨️ 快捷键说明

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