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

📄 bytebuffer.java

📁 apache 的一个socket框架
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    public abstract ByteBuffer duplicate();    /**     * @see java.nio.ByteBuffer#slice()     */    public abstract ByteBuffer slice();    /**     * @see java.nio.ByteBuffer#asReadOnlyBuffer()     */    public abstract ByteBuffer asReadOnlyBuffer();    /**     * @see java.nio.ByteBuffer#array()     */    public abstract byte[] array();    /**     * @see java.nio.ByteBuffer#arrayOffset()     */    public abstract int arrayOffset();    /**     * @see java.nio.ByteBuffer#get()     */    public abstract byte get();    /**     * Reads one unsigned byte as a short integer.     */    public short getUnsigned() {        return (short) (get() & 0xff);    }    /**     * @see java.nio.ByteBuffer#put(byte)     */    public abstract ByteBuffer put(byte b);    /**     * @see java.nio.ByteBuffer#get(int)     */    public abstract byte get(int index);    /**     * Reads one byte as an unsigned short integer.     */    public short getUnsigned(int index) {        return (short) (get(index) & 0xff);    }    /**     * @see java.nio.ByteBuffer#put(int, byte)     */    public abstract ByteBuffer put(int index, byte b);    /**     * @see java.nio.ByteBuffer#get(byte[], int, int)     */    public abstract ByteBuffer get(byte[] dst, int offset, int length);    /**     * @see java.nio.ByteBuffer#get(byte[])     */    public ByteBuffer get(byte[] dst) {        return get(dst, 0, dst.length);    }    /**     * Writes the content of the specified <tt>src</tt> into this buffer.     */    public abstract ByteBuffer put(java.nio.ByteBuffer src);    /**     * Writes the content of the specified <tt>src</tt> into this buffer.     */    public ByteBuffer put(ByteBuffer src) {        return put(src.buf());    }    /**     * @see java.nio.ByteBuffer#put(byte[], int, int)     */    public abstract ByteBuffer put(byte[] src, int offset, int length);    /**     * @see java.nio.ByteBuffer#put(byte[])     */    public ByteBuffer put(byte[] src) {        return put(src, 0, src.length);    }    /**     * @see java.nio.ByteBuffer#compact()     */    public abstract ByteBuffer compact();    public String toString() {        StringBuffer buf = new StringBuffer();        if (isDirect()) {            buf.append("DirectBuffer");        } else {            buf.append("HeapBuffer");        }        buf.append("[pos=");        buf.append(position());        buf.append(" lim=");        buf.append(limit());        buf.append(" cap=");        buf.append(capacity());        buf.append(": ");        buf.append(getHexDump());        buf.append(']');        return buf.toString();    }    public int hashCode() {        int h = 1;        int p = position();        for (int i = limit() - 1; i >= p; i--) {            h = 31 * h + get(i);        }        return h;    }    public boolean equals(Object o) {        if (!(o instanceof ByteBuffer)) {            return false;        }        ByteBuffer that = (ByteBuffer) o;        if (this.remaining() != that.remaining()) {            return false;        }        int p = this.position();        for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) {            byte v1 = this.get(i);            byte v2 = that.get(j);            if (v1 != v2) {                return false;            }        }        return true;    }    public int compareTo(ByteBuffer that) {        int n = this.position() + Math.min(this.remaining(), that.remaining());        for (int i = this.position(), j = that.position(); i < n; i++, j++) {            byte v1 = this.get(i);            byte v2 = that.get(j);            if (v1 == v2) {                continue;            }            if (v1 < v2) {                return -1;            }            return +1;        }        return this.remaining() - that.remaining();    }    /**     * @see java.nio.ByteBuffer#order()     */    public abstract ByteOrder order();    /**     * @see java.nio.ByteBuffer#order(ByteOrder)     */    public abstract ByteBuffer order(ByteOrder bo);    /**     * @see java.nio.ByteBuffer#getChar()     */    public abstract char getChar();    /**     * @see java.nio.ByteBuffer#putChar(char)     */    public abstract ByteBuffer putChar(char value);    /**     * @see java.nio.ByteBuffer#getChar(int)     */    public abstract char getChar(int index);    /**     * @see java.nio.ByteBuffer#putChar(int, char)     */    public abstract ByteBuffer putChar(int index, char value);    /**     * @see java.nio.ByteBuffer#asCharBuffer()     */    public abstract CharBuffer asCharBuffer();    /**     * @see java.nio.ByteBuffer#getShort()     */    public abstract short getShort();    /**     * Reads two bytes unsigned integer.     */    public int getUnsignedShort() {        return getShort() & 0xffff;    }    /**     * @see java.nio.ByteBuffer#putShort(short)     */    public abstract ByteBuffer putShort(short value);    /**     * @see java.nio.ByteBuffer#getShort()     */    public abstract short getShort(int index);    /**     * Reads two bytes unsigned integer.     */    public int getUnsignedShort(int index) {        return getShort(index) & 0xffff;    }    /**     * @see java.nio.ByteBuffer#putShort(int, short)     */    public abstract ByteBuffer putShort(int index, short value);    /**     * @see java.nio.ByteBuffer#asShortBuffer()     */    public abstract ShortBuffer asShortBuffer();    /**     * @see java.nio.ByteBuffer#getInt()     */    public abstract int getInt();    /**     * Reads four bytes unsigned integer.     */    public long getUnsignedInt() {        return getInt() & 0xffffffffL;    }    /**     * @see java.nio.ByteBuffer#putInt(int)     */    public abstract ByteBuffer putInt(int value);    /**     * @see java.nio.ByteBuffer#getInt(int)     */    public abstract int getInt(int index);    /**     * Reads four bytes unsigned integer.     */    public long getUnsignedInt(int index) {        return getInt(index) & 0xffffffffL;    }    /**     * @see java.nio.ByteBuffer#putInt(int, int)     */    public abstract ByteBuffer putInt(int index, int value);    /**     * @see java.nio.ByteBuffer#asIntBuffer()     */    public abstract IntBuffer asIntBuffer();    /**     * @see java.nio.ByteBuffer#getLong()     */    public abstract long getLong();    /**     * @see java.nio.ByteBuffer#putLong(int, long)     */    public abstract ByteBuffer putLong(long value);    /**     * @see java.nio.ByteBuffer#getLong(int)     */    public abstract long getLong(int index);    /**     * @see java.nio.ByteBuffer#putLong(int, long)     */    public abstract ByteBuffer putLong(int index, long value);    /**     * @see java.nio.ByteBuffer#asLongBuffer()     */    public abstract LongBuffer asLongBuffer();    /**     * @see java.nio.ByteBuffer#getFloat()     */    public abstract float getFloat();    /**     * @see java.nio.ByteBuffer#putFloat(float)     */    public abstract ByteBuffer putFloat(float value);    /**     * @see java.nio.ByteBuffer#getFloat(int)     */    public abstract float getFloat(int index);    /**     * @see java.nio.ByteBuffer#putFloat(int, float)     */    public abstract ByteBuffer putFloat(int index, float value);    /**     * @see java.nio.ByteBuffer#asFloatBuffer()     */    public abstract FloatBuffer asFloatBuffer();    /**     * @see java.nio.ByteBuffer#getDouble()     */    public abstract double getDouble();    /**     * @see java.nio.ByteBuffer#putDouble(double)     */    public abstract ByteBuffer putDouble(double value);    /**     * @see java.nio.ByteBuffer#getDouble(int)     */    public abstract double getDouble(int index);    /**     * @see java.nio.ByteBuffer#putDouble(int, double)     */    public abstract ByteBuffer putDouble(int index, double value);    /**     * @see java.nio.ByteBuffer#asDoubleBuffer()     */    public abstract DoubleBuffer asDoubleBuffer();    /**     * Returns an {@link InputStream} that reads the data from this buffer.     * {@link InputStream#read()} returns <tt>-1</tt> if the buffer position     * reaches to the limit.     */    public InputStream asInputStream() {        return new InputStream() {            public int available() {                return ByteBuffer.this.remaining();            }            public synchronized void mark(int readlimit) {                ByteBuffer.this.mark();            }            public boolean markSupported() {                return true;            }            public int read() {                if (ByteBuffer.this.hasRemaining()) {                    return ByteBuffer.this.get() & 0xff;                } else {                    return -1;                }            }            public int read(byte[] b, int off, int len) {                int remaining = ByteBuffer.this.remaining();                if (remaining > 0) {                    int readBytes = Math.min(remaining, len);                    ByteBuffer.this.get(b, off, readBytes);                    return readBytes;                } else {                    return -1;                }            }            public synchronized void reset() {                ByteBuffer.this.reset();            }            public long skip(long n) {                int bytes;                if (n > Integer.MAX_VALUE) {                    bytes = ByteBuffer.this.remaining();                } else {                    bytes = Math.min(ByteBuffer.this.remaining(), (int) n);                }                ByteBuffer.this.skip(bytes);                return bytes;            }        };    }    /**     * Returns an {@link OutputStream} that appends the data into this buffer.     * Please note that the {@link OutputStream#write(int)} will throw a     * {@link BufferOverflowException} instead of an {@link IOException}     * in case of buffer overflow.  Please set <tt>autoExpand</tt> property by     * calling {@link #setAutoExpand(boolean)} to prevent the unexpected runtime     * exception.     */    public OutputStream asOutputStream() {        return new OutputStream() {            public void write(byte[] b, int off, int len) {                ByteBuffer.this.put(b, off, len);            }            public void write(int b) {                ByteBuffer.this.put((byte) b);            }        };    }    /**     * Returns hexdump of this buffer.     */    public String getHexDump() {        return ByteBufferHexDumper.getHexdump(this);    }

⌨️ 快捷键说明

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