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

📄 characterstreams.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}		System.out.print(sb.toString());	}	private static void checkAsciiStreams(PreparedStatement psDel, PreparedStatement psi, PreparedStatement psq2,				int cl, int vcl, int lvcl)				throws SQLException, java.io.IOException {		psDel.executeUpdate();		// now insert long values using streams and check them programatically.		psi.setAsciiStream(1, new c3AsciiStream(cl), cl);		psi.setAsciiStream(2, new c3AsciiStream(vcl), vcl);		psi.setAsciiStream(3, new c3AsciiStream(lvcl), lvcl);		psi.executeUpdate();		ResultSet rs = psq2.executeQuery();		rs.next();		InputStream is = rs.getAsciiStream(1);		System.out.print("AS-CHAR-" + cl + " ");		c3AsciiStream.check(is, cl, 25);		System.out.println("DONE");		is = rs.getAsciiStream(2);		System.out.print("AS-VARCHAR-" + vcl + " ");		c3AsciiStream.check(is, vcl, -1);		System.out.println("DONE");		is = rs.getAsciiStream(3);		System.out.print("AS-LONG VARCHAR-" + lvcl + " ");		c3AsciiStream.check(is, lvcl, -1);		System.out.println("DONE");		rs.close();				rs = psq2.executeQuery();		rs.next();		Reader r = rs.getCharacterStream(1);		System.out.print("CS-CHAR-" + cl + " ");		c3AsciiStream.check(r, cl, 25);		System.out.println("DONE");		r = rs.getCharacterStream(2);		System.out.print("CS-VARCHAR-" + vcl + " ");		c3AsciiStream.check(r, vcl, -1);		System.out.println("DONE");		r = rs.getCharacterStream(3);		System.out.print("CS-LONG VARCHAR-" + lvcl + " ");		c3AsciiStream.check(r, lvcl, -1);		System.out.println("DONE");		rs.close();		// and check as Strings		rs = psq2.executeQuery();		rs.next();		r = new java.io.StringReader(rs.getString(1));		System.out.print("ST-CHAR-" + cl + " ");		c3AsciiStream.check(r, cl, 25);		System.out.println("DONE");		r = new java.io.StringReader(rs.getString(2));		System.out.print("ST-VARCHAR-" + vcl + " ");		c3AsciiStream.check(r, vcl, -1);		System.out.println("DONE");		r = new java.io.StringReader(rs.getString(3));		System.out.print("ST-LONG VARCHAR-" + lvcl + " ");		c3AsciiStream.check(r, lvcl, -1);		System.out.println("DONE");		rs.close();		}	private static void checkCharacterStreams(PreparedStatement psDel, PreparedStatement psi, PreparedStatement psq2,				int cl, int vcl, int lvcl)				throws SQLException, java.io.IOException {		psDel.executeUpdate();		psi.setCharacterStream(1, new c3Reader(cl), cl);		psi.setCharacterStream(2, new c3Reader(vcl), vcl);		psi.setCharacterStream(3, new c3Reader(lvcl), lvcl);		psi.executeUpdate();		ResultSet rs = psq2.executeQuery();		rs.next();		InputStream is = rs.getAsciiStream(1);		System.out.print("AS-CHAR-" + cl + " ");		c3Reader.check(is, cl, 25);		System.out.println("DONE");		is = rs.getAsciiStream(2);		System.out.print("AS-VARCHAR-" + vcl + " ");		c3Reader.check(is, vcl, -1);		System.out.println("DONE");		is = rs.getAsciiStream(3);		System.out.print("AS-LONG VARCHAR-" + lvcl + " ");		c3Reader.check(is, lvcl, -1);		System.out.println("DONE");		rs.close();				rs = psq2.executeQuery();		rs.next();		Reader r = rs.getCharacterStream(1);		System.out.print("CS-CHAR-" + cl + " ");		c3Reader.check(r, cl, 25);		System.out.println("DONE");		r = rs.getCharacterStream(2);		System.out.print("CS-VARCHAR-" + vcl + " ");		c3Reader.check(r, vcl, -1);		System.out.println("DONE");		r = rs.getCharacterStream(3);		System.out.print("CS-LONG VARCHAR-" + lvcl + " ");		c3Reader.check(r, lvcl, -1);		System.out.println("DONE");		rs.close();		// check converting them into Strings work		rs = psq2.executeQuery();		rs.next();		String suv = rs.getString(1);		r = new java.io.StringReader(suv);		System.out.print("ST-CHAR-" + cl + " ");		c3Reader.check(r, cl, 25);		System.out.println("DONE");		suv = rs.getString(2);		r = new java.io.StringReader(suv);		System.out.print("ST-VARCHAR-" + vcl + " ");		c3Reader.check(r, vcl, -1);		System.out.println("DONE");		suv = rs.getString(3);		r = new java.io.StringReader(suv);		System.out.print("ST-LONG VARCHAR-" + lvcl + " ");		c3Reader.check(r, lvcl, -1);		System.out.println("DONE");		rs.close();		}}class c3AsciiStream extends java.io.InputStream {	private final int size;	private int count;	c3AsciiStream(int size) {		this.size = size;	}	public int read(byte[] buf, int off, int length) {		if (count >= size)			return -1;		if (length > (size - count))			length = (size - count);		// ensure the readers don't always get a full buffer,		// makes sure they are not assuming the buffer will be filled.		if (length > 20)			length -= 17;		for (int i = 0; i < length ; i++) {			buf[off + i] = (byte) count++;		}		return length;	}	private byte[] rd = new byte[1];	public int read() {		int read = read(rd, 0, 1);		if (read == -1)			return -1;		return rd[0] & 0xFF;	}	public void close() {	}	static void check(InputStream is, int length, int fixedLen) throws java.io.IOException {		InputStream orig = new c3AsciiStream(length);		int count = 0;		for (;;) {			int o = orig == null ? (count == fixedLen ? -2 : 0x20) : orig.read();			int c = is.read();			if (o == -1) {				orig = null;				if (fixedLen != -1 && fixedLen != length)					o = ' ';			}			if (o == -2)				o = -1;			if ((byte) o != (byte) c) {				System.out.print("F@" + count +"("+((byte)o)+","+((byte)c)+")");			}			if (orig == null) {				if (fixedLen == -1)					break;			}			if (c == -1 && fixedLen != -1)				break;						count++;		}		if (fixedLen != -1)			length = fixedLen;		if (count != length) {			System.out.print("FAIL-LEN" + count + " expected " + length);		}		is.close();	}	static void check(Reader r, int length, int fixedLen) throws java.io.IOException {		InputStream orig = new c3AsciiStream(length);		int count = 0;		for (;;) {			int o = orig == null ? (count == fixedLen ? -2 : 0x20) : orig.read();			int c = r.read();			if (o == -1) {				orig = null;				if (fixedLen != -1 && fixedLen != length)					o = ' ';			}			if (o == -2)				o = -1;			if (o != c) {				System.out.print("F@" + count +"("+o+","+c+")");			}			if (orig == null) {				if (fixedLen == -1)					break;			}			if (c == -1 && fixedLen != -1)				break;						count++;		}		if (fixedLen != -1)			length = fixedLen;		if (count != length) {			System.out.print("FAIL-LEN" + count + " expected " + length);		}		r.close();	}}class c3Reader extends java.io.Reader {	private final int size;	private int count;	c3Reader(int size) {		this.size = size;	}	public int read(char[] buf, int off, int length) {		if (count >= size)			return -1;		if (length > (size - count))			length = (size - count);		// ensure the readers don't always get a full buffer,		// makes sure they are not assuming the buffer will be filled.		if (length > 20)			length -= 17;		for (int i = 0; i < length ; i++) {			char c;			switch (count % 3) {			case 0:				c = (char) (count & 0x7F); // one byte UTF8				break;			case 1:				c = (char) ((count + 0x7F) & 0x07FF); // two byte UTF8				break;			default:			case 2:				c = (char) (count + 0x07FF); // three byte UTF8				break;			}			buf[off + i] = c;			count++;		}		return length;	}	public void close() {	}	static void check(InputStream is, int length, int fixedLen) throws java.io.IOException {		Reader orig = new c3Reader(length);		int count = 0;		for (;;) {			int o = orig == null ? (count == fixedLen ? -2 : 0x20) : orig.read();			int c = is.read();			if (o == -1) {				orig = null;				if (fixedLen != -1 && fixedLen != length)					o = ' ';			}			if (o == -2)				o = -1;			if (o != -1) {				if (o <= 255)					o = o & 0xFF; // convert to single byte exended ASCII				else					o = '?'; // out of range character.			}			if (o != c) {				System.out.print("F@" + count +"("+o+","+c+")");			}			if (orig == null) {				if (fixedLen == -1)					break;			}			if (c == -1 && fixedLen != -1)				break;						count++;		}		if (fixedLen != -1)			length = fixedLen;		if (count != length) {			System.out.print("FAIL-LEN" + count + " expected " + length);		}		is.close();	}	static void check(Reader r, int length, int fixedLen) throws java.io.IOException {		Reader orig = new c3Reader(length);		int count = 0;		for (;;) {			int o = orig == null ? (count == fixedLen ? -2 : 0x20) : orig.read();			int c = r.read();			if (o == -1) {				orig = null;				if (fixedLen != -1 && fixedLen != length)					o = ' ';			}			if (o == -2)				o = -1;			if (o != c) {				System.out.print("F@" + count +"("+o+","+c+")");			}			if (orig == null) {				if (fixedLen == -1)					break;			}			if (c == -1 && fixedLen != -1)				break;						count++;		}		if (fixedLen != -1)			length = fixedLen;		if (count != length) {			System.out.print("FAIL-LEN" + count + " expected " + length);		}		r.close();	}}

⌨️ 快捷键说明

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