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

📄 tupleinput.java

📁 berkeleyDB,强大的嵌入式数据,多个数据库的内核
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Reads values that were written using {@link TupleOutput#writeDouble}.     * <code>Double.longBitsToDouble</code> is used to convert the signed long     * value.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final double readDouble() throws IndexOutOfBoundsException {        return Double.longBitsToDouble(readUnsignedLong());    }    /**     * Reads an unsigned byte (one byte) value from the buffer.     * Reads values that were written using {@link     * TupleOutput#writeUnsignedByte}.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final int readUnsignedByte() throws IndexOutOfBoundsException {        int c = readFast();        if (c < 0) {            throw new IndexOutOfBoundsException();        }        return c;    }    /**     * Reads an unsigned short (two byte) value from the buffer.     * Reads values that were written using {@link     * TupleOutput#writeUnsignedShort}.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final int readUnsignedShort() throws IndexOutOfBoundsException {        int c1 = readFast();        int c2 = readFast();        if ((c1 | c2) < 0) {             throw new IndexOutOfBoundsException();        }        return ((c1 << 8) | c2);    }    // --- end DataInput compatible methods ---    /**     * Reads an unsigned int (four byte) value from the buffer.     * Reads values that were written using {@link     * TupleOutput#writeUnsignedInt}.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final long readUnsignedInt() throws IndexOutOfBoundsException {        long c1 = readFast();        long c2 = readFast();        long c3 = readFast();        long c4 = readFast();        if ((c1 | c2 | c3 | c4) < 0) {             throw new IndexOutOfBoundsException();        }        return ((c1 << 24) | (c2 << 16) | (c3 << 8) | c4);    }    /**     * This method is private since an unsigned long cannot be treated as     * such in Java, nor converted to a BigInteger of the same value.     */    private final long readUnsignedLong() throws IndexOutOfBoundsException {        long c1 = readFast();        long c2 = readFast();        long c3 = readFast();        long c4 = readFast();        long c5 = readFast();        long c6 = readFast();        long c7 = readFast();        long c8 = readFast();        if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) < 0) {             throw new IndexOutOfBoundsException();        }        return ((c1 << 56) | (c2 << 48) | (c3 << 40) | (c4 << 32) |                (c5 << 24) | (c6 << 16) | (c7 << 8)  | c8);    }    /**     * Reads the specified number of bytes from the buffer, converting each     * unsigned byte value to a character of the resulting string.     * Reads values that were written using {@link TupleOutput#writeBytes}.     * Only characters with values below 0x100 may be read using this method.     *     * @param length is the number of bytes to be read.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final String readBytes(int length)        throws IndexOutOfBoundsException {        StringBuffer buf = new StringBuffer(length);        for (int i = 0; i < length; i++) {            int c = readFast();            if (c < 0) {                throw new IndexOutOfBoundsException();            }            buf.append((char) c);        }        return buf.toString();    }    /**     * Reads the specified number of characters from the buffer, converting     * each two byte unsigned value to a character of the resulting string.     * Reads values that were written using {@link TupleOutput#writeChars}.     *     * @param length is the number of characters to be read.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final String readChars(int length)        throws IndexOutOfBoundsException {        StringBuffer buf = new StringBuffer(length);        for (int i = 0; i < length; i++) {            buf.append(readChar());        }        return buf.toString();    }    /**     * Reads the specified number of bytes from the buffer, converting each     * unsigned byte value to a character of the resulting array.     * Reads values that were written using {@link TupleOutput#writeBytes}.     * Only characters with values below 0x100 may be read using this method.     *     * @param chars is the array to receive the data and whose length is used     * to determine the number of bytes to be read.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final void readBytes(char[] chars)        throws IndexOutOfBoundsException {        for (int i = 0; i < chars.length; i++) {            int c = readFast();            if (c < 0) {                throw new IndexOutOfBoundsException();            }            chars[i] = (char) c;        }    }    /**     * Reads the specified number of characters from the buffer, converting     * each two byte unsigned value to a character of the resulting array.     * Reads values that were written using {@link TupleOutput#writeChars}.     *     * @param chars is the array to receive the data and whose length is used     * to determine the number of characters to be read.     *     * @return the value read from the buffer.     *     * @throws IndexOutOfBoundsException if not enough bytes are available in     * the buffer.     */    public final void readChars(char[] chars)        throws IndexOutOfBoundsException {        for (int i = 0; i < chars.length; i++) {            chars[i] = readChar();        }    }    /**     * Reads the specified number of UTF characters string from the data     * buffer and converts the data from UTF to Unicode.     * Reads values that were written using {@link     * TupleOutput#writeString(char[])}.     *     * @param length is the number of characters to be read.     *     * @return the converted string.     *     * @throws IndexOutOfBoundsException if no null terminating byte is found     * in the buffer.     *     * @throws IllegalArgumentException malformed UTF data is encountered.     */    public final String readString(int length)        throws IndexOutOfBoundsException, IllegalArgumentException  {        char[] chars = new char[length];        readString(chars);        return new String(chars);    }    /**     * Reads the specified number of UTF characters string from the data     * buffer and converts the data from UTF to Unicode.     * Reads values that were written using {@link     * TupleOutput#writeString(char[])}.     *     * @param chars is the array to receive the data and whose length is used     * to determine the number of characters to be read.     *     * @return the converted string.     *     * @throws IndexOutOfBoundsException if no null terminating byte is found     * in the buffer.     *     * @throws IllegalArgumentException malformed UTF data is encountered.     */    public final void readString(char[] chars)        throws IndexOutOfBoundsException, IllegalArgumentException  {        byte[] buf = getBufferBytes();        off = UtfOps.bytesToChars(buf, off, chars, 0, chars.length, false);    }}

⌨️ 快捷键说明

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