/**
* Demonstrates that skipping incorrectly encoded character sequences
* works because the stream is not checked for well-formedness.
*/
public void testSkippingInvalidEncodingWorks()
throws IOException {
// The array contains three valid characters and one invalid three-byte
// representation that only has two bytes present.
// When skipping, this sequence is (incorrectly) taken as a sequence of
// three characters ('a' - some three byte character - 'a').
// 0xef = 11101111, 0xb8 = 10111000
byte[] data = {'a', (byte)0xef, (byte)0xb8, 'a', 'a'};
byte[] dataWithLength =
{0x0, 0x5, 'a', (byte)0xef, (byte)0xb8, 'a', 'a'};
InputStream is = new ByteArrayInputStream(data);
// This is actually incorrect, but does work currently.
UTF8Util.skipFully(is, 3);
// Verify that decoding this actually fails.
DataInputStream dis = new DataInputStream(
new ByteArrayInputStream(dataWithLength));
try {
dis.readUTF();
fail("UTF-8 expected to be invalid, read should fail");
} catch (UTFDataFormatException udfe) {
// This is expected, since the UTF-8 encoding is invalid
}
}
UTF8UtilTest.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:gemfirexd-oss
作者:
评论列表
文章目录