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

📄 bytearraybuffer.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        | ((b[this.position++] & 0xff) << 24);    }    // 2000-06-05 Changed    final int readLongInt() {        byte[] b = this.byteBuffer;        return (b[this.position++] & 0xff) | ((b[this.position++] & 0xff) << 8)        | ((b[this.position++] & 0xff) << 16);    }    // 2000-06-05 Fixed    final long readLongLong() {        byte[] b = this.byteBuffer;        return (b[this.position++] & 0xff)        | ((long) (b[this.position++] & 0xff) << 8)        | ((long) (b[this.position++] & 0xff) << 16)        | ((long) (b[this.position++] & 0xff) << 24)        | ((long) (b[this.position++] & 0xff) << 32)        | ((long) (b[this.position++] & 0xff) << 40)        | ((long) (b[this.position++] & 0xff) << 48)        | ((long) (b[this.position++] & 0xff) << 56);    }    //    // Read a null-terminated string    //    // To avoid alloc'ing a new byte array, we    // do this by hand, rather than calling getNullTerminatedBytes()    //    final String readString() {        int i = this.position;        int len = 0;		int maxLen = getBufLength();		        while ((i < maxLen) && (this.byteBuffer[i] != 0)) {            len++;            i++;        }        String s = new String(this.byteBuffer, this.position, len);        this.position += (len + 1); // update cursor        return s;    }    final String readString(String encoding) throws SQLException {        int i = this.position;        int len = 0;		int maxLen = getBufLength();				while ((i < maxLen) && (this.byteBuffer[i] != 0)) {            len++;            i++;        }        try {            return new String(this.byteBuffer, this.position, len, encoding);        } catch (UnsupportedEncodingException uEE) {            throw new SQLException(Messages.getString("ByteArrayBuffer.1") //$NON-NLS-1$                + encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$        } finally {            this.position += (len + 1); // update cursor        }    }    final int readnBytes() {        int sw = this.byteBuffer[this.position++] & 0xff;        switch (sw) {        case 1:            return this.byteBuffer[this.position++] & 0xff;        case 2:            return this.readInt();        case 3:            return this.readLongInt();        case 4:            return (int) this.readLong();        default:            return 255;        }    }    final void writeByte(byte b) throws SQLException {        ensureCapacity(1);        this.byteBuffer[this.position++] = b;    }    // Write a byte array    final void writeBytesNoNull(byte[] bytes) throws SQLException {        int len = bytes.length;        ensureCapacity(len);        System.arraycopy(bytes, 0, this.byteBuffer, this.position, len);        this.position += len;    }    // Write a byte array with the given offset and length    final void writeBytesNoNull(byte[] bytes, int offset, int length)        throws SQLException {        ensureCapacity(length);        System.arraycopy(bytes, offset, this.byteBuffer, this.position, length);        this.position += length;    }    final void writeDouble(double d) throws SQLException {        long l = Double.doubleToLongBits(d);        writeLongLong(l);    }    final void writeFieldLength(long length) throws SQLException {        if (length < 251) {            writeByte((byte) length);        } else if (length < 65536L) {            ensureCapacity(3);            writeByte((byte) 252);            writeInt((int) length);        } else if (length < 16777216L) {            ensureCapacity(4);            writeByte((byte) 253);            writeLongInt((int) length);        } else {            ensureCapacity(9);            writeByte((byte) 254);            writeLongLong(length);        }    }    final void writeFloat(float f) throws SQLException {    	ensureCapacity(4);    	        int i = Float.floatToIntBits(f);        byte[] b = this.byteBuffer;        b[this.position++] = (byte) (i & 0xff);        b[this.position++] = (byte) (i >>> 8);        b[this.position++] = (byte) (i >>> 16);        b[this.position++] = (byte) (i >>> 24);    }    // 2000-06-05 Changed    final void writeInt(int i) throws SQLException {    	ensureCapacity(2);    	        byte[] b = this.byteBuffer;        b[this.position++] = (byte) (i & 0xff);        b[this.position++] = (byte) (i >>> 8);    }    //	Write a String using the specified character    // encoding    final void writeLenBytes(byte[] b) throws SQLException {        int len = b.length;        ensureCapacity(len + 9);        writeFieldLength(len);        System.arraycopy(b, 0, this.byteBuffer, this.position, len);        this.position += len;    }    //	Write a String using the specified character    // encoding    final void writeLenString(String s, String encoding, String serverEncoding,     		SingleByteCharsetConverter converter, boolean parserKnowsUnicode)        throws UnsupportedEncodingException, SQLException {        byte[] b = null;                if (converter != null) {            b = converter.toBytes(s);        } else {            b = StringUtils.getBytes(s, encoding, serverEncoding, parserKnowsUnicode);        }        int len = b.length;        ensureCapacity(len + 9);        writeFieldLength(len);        System.arraycopy(b, 0, this.byteBuffer, this.position, len);        this.position += len;    }    // 2000-06-05 Changed    final void writeLong(long i) throws SQLException {    	ensureCapacity(4);    	        byte[] b = this.byteBuffer;        b[this.position++] = (byte) (i & 0xff);        b[this.position++] = (byte) (i >>> 8);        b[this.position++] = (byte) (i >>> 16);        b[this.position++] = (byte) (i >>> 24);    }    // 2000-06-05 Changed    final void writeLongInt(int i) throws SQLException {		ensureCapacity(3);        byte[] b = this.byteBuffer;        b[this.position++] = (byte) (i & 0xff);        b[this.position++] = (byte) (i >>> 8);        b[this.position++] = (byte) (i >>> 16);    }    final void writeLongLong(long i) throws SQLException {    	ensureCapacity(8);        byte[] b = this.byteBuffer;        b[this.position++] = (byte) (i & 0xff);        b[this.position++] = (byte) (i >>> 8);        b[this.position++] = (byte) (i >>> 16);        b[this.position++] = (byte) (i >>> 24);        b[this.position++] = (byte) (i >>> 32);        b[this.position++] = (byte) (i >>> 40);        b[this.position++] = (byte) (i >>> 48);        b[this.position++] = (byte) (i >>> 56);    }    // Write null-terminated string    final void writeString(String s) throws SQLException {        ensureCapacity((s.length() * 2) + 1);        writeStringNoNull(s);        this.byteBuffer[this.position++] = 0;    }    // Write string, with no termination    final void writeStringNoNull(String s) throws SQLException {        int len = s.length();        ensureCapacity(len * 2);        System.arraycopy(s.getBytes(), 0, this.byteBuffer, this.position, len);        this.position += len;        //         for (int i = 0; i < len; i++)        //         {        //             this.byteBuffer[this.position++] = (byte)s.charAt(i);        //         }    }    // Write a String using the specified character    // encoding    final void writeStringNoNull(String s, String encoding, String serverEncoding,    		boolean parserKnowsUnicode)        throws UnsupportedEncodingException, SQLException {        byte[] b = StringUtils.getBytes(s, encoding, serverEncoding, parserKnowsUnicode);        int len = b.length;        ensureCapacity(len);        System.arraycopy(b, 0, this.byteBuffer, this.position, len);        this.position += len;    }    void setBufLength(int bufLengthToSet) {        this.bufLength = bufLengthToSet;    }    int getBufLength() {        return this.bufLength;    }	int getCapacity() {		return this.byteBuffer.length;	}	/* (non-Javadoc)	 * @see com.mysql.jdbc.Buffer#getBytes(int, int)	 */	byte[] getBytes(int offset, int len) {		byte[] dest = new byte[len];		System.arraycopy(this.byteBuffer, offset, dest, 0, len);				return dest;	}}

⌨️ 快捷键说明

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