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

📄 tupleoutput.java

📁 关于Berkelay数据库的共享源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Writes an signed float (four byte) value to the buffer.     * Writes values that can be read using {@link TupleInput#readFloat}.     * <code>Float.floatToIntBits</code> is used to convert the signed float     * value.     *     * <p><em>Note:</em> This method produces byte array values that by default     * (without a custom comparator) do <em>not</em> sort correctly for     * negative values.  Only non-negative values are sorted correctly by     * default.  To sort all values correctly by default, use {@link     * #writeSortedFloat}.</p>     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeFloat(float val) {        writeUnsignedInt(Float.floatToIntBits(val));        return this;    }    /**     * Writes an signed double (eight byte) value to the buffer.     * Writes values that can be read using {@link TupleInput#readDouble}.     * <code>Double.doubleToLongBits</code> is used to convert the signed     * double value.     *     * <p><em>Note:</em> This method produces byte array values that by default     * (without a custom comparator) do <em>not</em> sort correctly for     * negative values.  Only non-negative values are sorted correctly by     * default.  To sort all values correctly by default, use {@link     * #writeSortedDouble}.</p>     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeDouble(double val) {        writeUnsignedLong(Double.doubleToLongBits(val));        return this;    }    /**     * Writes a signed float (four byte) value to the buffer, with support for     * correct default sorting of all values.     * Writes values that can be read using {@link TupleInput#readSortedFloat}.     *     * <p><code>Float.floatToIntBits</code> and the following bit manipulations     * are used to convert the signed float value to a representation that is     * sorted correctly by default.</p>     * <pre>     *  int intVal = Float.floatToIntBits(val);     *  intVal ^= (intVal &lt; 0) ? 0xffffffff : 0x80000000;     * </pre>     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeSortedFloat(float val) {        int intVal = Float.floatToIntBits(val);        intVal ^= (intVal < 0) ? 0xffffffff : 0x80000000;        writeUnsignedInt(intVal);        return this;    }    /**     * Writes a signed double (eight byte) value to the buffer, with support     * for correct default sorting of all values.     * Writes values that can be read using {@link TupleInput#readSortedDouble}.     *     * <p><code>Float.doubleToLongBits</code> and the following bit     * manipulations are used to convert the signed double value to a     * representation that is sorted correctly by default.</p>     * <pre>     *  long longVal = Double.doubleToLongBits(val);     *  longVal ^= (longVal &lt; 0) ? 0xffffffffffffffffL : 0x8000000000000000L;     * </pre>     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeSortedDouble(double val) {        long longVal = Double.doubleToLongBits(val);        longVal ^= (longVal < 0) ? 0xffffffffffffffffL : 0x8000000000000000L;        writeUnsignedLong(longVal);        return this;    }    // --- end DataOutput compatible methods ---    /**     * Writes the specified bytes to the buffer, converting each character to     * an unsigned byte value.     * Writes values that can be read using {@link TupleInput#readBytes}.     * Only characters with values below 0x100 may be written using this     * method, since the high-order 8 bits of all characters are discarded.     *     * @param chars is the array of values to be written.     *     * @return this tuple output object.     *     * @throws NullPointerException if the chars parameter is null.     */    public final TupleOutput writeBytes(char[] chars) {        for (int i = 0; i < chars.length; i++) {            writeFast((byte) chars[i]);        }        return this;    }    /**     * Writes the specified characters to the buffer, converting each character     * to a two byte unsigned value.     * Writes values that can be read using {@link TupleInput#readChars}.     *     * @param chars is the array of characters to be written.     *     * @return this tuple output object.     *     * @throws NullPointerException if the chars parameter is null.     */    public final TupleOutput writeChars(char[] chars) {        for (int i = 0; i < chars.length; i++) {            writeFast((byte) (chars[i] >>> 8));            writeFast((byte) chars[i]);        }        return this;    }    /**     * Writes the specified characters to the buffer, converting each character     * to UTF format.     * Note that zero (0x0000) character values are encoded as non-zero values.     * Writes values that can be read using {@link TupleInput#readString(int)}     * or {@link TupleInput#readString(char[])}.     *     * @param chars is the array of characters to be written.     *     * @return this tuple output object.     *     * @throws NullPointerException if the chars parameter is null.     */    public final TupleOutput writeString(char[] chars) {        if (chars.length == 0) return this;        int utfLength = UtfOps.getByteLength(chars);        makeSpace(utfLength);        UtfOps.charsToBytes(chars, 0, getBufferBytes(), getBufferLength(),                            chars.length);        addSize(utfLength);        return this;    }    /**     * Writes an unsigned byte (one byte) value to the buffer.     * Writes values that can be read using {@link     * TupleInput#readUnsignedByte}.     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeUnsignedByte(int val) {        writeFast(val);        return this;    }    /**     * Writes an unsigned short (two byte) value to the buffer.     * Writes values that can be read using {@link     * TupleInput#readUnsignedShort}.     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeUnsignedShort(int val) {        writeFast((byte) (val >>> 8));        writeFast((byte) val);        return this;    }    /**     * Writes an unsigned int (four byte) value to the buffer.     * Writes values that can be read using {@link     * TupleInput#readUnsignedInt}.     *     * @param val is the value to write to the buffer.     *     * @return this tuple output object.     */    public final TupleOutput writeUnsignedInt(long val) {        writeFast((byte) (val >>> 24));        writeFast((byte) (val >>> 16));        writeFast((byte) (val >>> 8));        writeFast((byte) val);        return this;    }    /**     * 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 TupleOutput writeUnsignedLong(long val) {        writeFast((byte) (val >>> 56));        writeFast((byte) (val >>> 48));        writeFast((byte) (val >>> 40));        writeFast((byte) (val >>> 32));        writeFast((byte) (val >>> 24));        writeFast((byte) (val >>> 16));        writeFast((byte) (val >>> 8));        writeFast((byte) val);        return this;    }    /**     * Writes a packed integer.  Note that packed integers are not appropriate     * for sorted values (keys) unless a custom comparator is used.     *     * @see PackedInteger     */    public void writePackedInt(int val) {        makeSpace(PackedInteger.MAX_LENGTH);        int oldLen = getBufferLength();        int newLen = PackedInteger.writeInt(getBufferBytes(), oldLen, val);        addSize(newLen - oldLen);    }}

⌨️ 快捷键说明

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