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

📄 buffer.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			return readInt();		case 253:			return readLongInt();		case 254:			return readLong();		default:			return sw;		}	}	// 2000-06-05 Fixed	final long readLong() {		byte[] b = this.byteBuffer;		return ((long) b[this.position++] & 0xff)				| (((long) b[this.position++] & 0xff) << 8)				| ((long) (b[this.position++] & 0xff) << 16)				| ((long) (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);	}	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;		}	}	//	// 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 SQLError.createSQLException(Messages.getString("ByteArrayBuffer.1") //$NON-NLS-1$					+ encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$		} finally {			this.position += (len + 1); // update cursor		}	}	void setBufLength(int bufLengthToSet) {		this.bufLength = bufLengthToSet;	}	/**	 * Sets the array of bytes to use as a buffer to read from.	 * 	 * @param byteBuffer	 *            the array of bytes to use as a buffer	 */	public void setByteBuffer(byte[] byteBufferToSet) {		this.byteBuffer = byteBufferToSet;	}	/**	 * Set the current position to write to/ read from	 * 	 * @param position	 *            the position (0-based index)	 */	public void setPosition(int positionToSet) {		this.position = positionToSet;	}	/**	 * Sets whether this packet was part of a multipacket	 * 	 * @param flag	 *            was this packet part of a multipacket?	 */	public void setWasMultiPacket(boolean flag) {		this.wasMultiPacket = flag;	}	public String toString() {		return dumpClampedBytes(getPosition());	}	public String toSuperString() {		return super.toString();	}	/**	 * Was this packet part of a multipacket?	 * 	 * @return was this packet part of a multipacket?	 */	public boolean wasMultiPacket() {		return this.wasMultiPacket;	}	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,			ConnectionImpl conn)			throws UnsupportedEncodingException, SQLException {		byte[] b = null;		if (converter != null) {			b = converter.toBytes(s);		} else {			b = StringUtils.getBytes(s, encoding, serverEncoding,					parserKnowsUnicode, conn);		}		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 null-terminated string in the given encoding	final void writeString(String s, String encoding, ConnectionImpl conn) throws SQLException {		ensureCapacity((s.length() * 2) + 1);		try {			writeStringNoNull(s, encoding, encoding, false, conn);		} catch (UnsupportedEncodingException ue) {			throw new SQLException(ue.toString(), SQLError.SQL_STATE_GENERAL_ERROR);		}				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, ConnectionImpl conn)			throws UnsupportedEncodingException, SQLException {		byte[] b = StringUtils.getBytes(s, encoding, serverEncoding,				parserKnowsUnicode, conn);		int len = b.length;		ensureCapacity(len);		System.arraycopy(b, 0, this.byteBuffer, this.position, len);		this.position += len;	}}

⌨️ 快捷键说明

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