Initial commit from SVN.
This commit is contained in:
185
Common Test/src/com/softwarezealot/common/io/test/Test.java
Normal file
185
Common Test/src/com/softwarezealot/common/io/test/Test.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package com.softwarezealot.common.io.test;
|
||||
|
||||
import com.common.system.SystemManager;
|
||||
import com.common.io.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999<p>
|
||||
*/
|
||||
public class Test {
|
||||
/**
|
||||
* Test constructor comment.
|
||||
*/
|
||||
public Test() {
|
||||
super();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//char t = '\uAAAA';
|
||||
//System.out.println("\\uAAAA\t" + ((int)t) + "\t" + 0xAAAA);
|
||||
printUnicode16ToUTF8HexCodes();
|
||||
//System.out.println("" + (0xFFFF));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
/**
|
||||
* see JDK documentation (JNI section) types.doc.html.
|
||||
*/
|
||||
public static void printUnicode16ToUTF8HexCodes() {
|
||||
try {
|
||||
byte[] character = new byte[2];
|
||||
char[] characters = new char[1];
|
||||
int max = 0xFFFF;
|
||||
String UTF8 = "UTF8";
|
||||
String Unicode = "Unicode";
|
||||
int count = 0;
|
||||
StringBuffer buffer = new StringBuffer(10000);
|
||||
byte[] oldUtf8 = null;
|
||||
int loopNumber = 0;
|
||||
|
||||
for(characters[0] = '\u0000'; characters[0] < max; characters[0]++, loopNumber++) {
|
||||
String str = new String(characters);
|
||||
byte[] utf8 = str.getBytes(UTF8);
|
||||
byte[] unicode16 = str.getBytes(Unicode);
|
||||
int intValue = (int) characters[0];
|
||||
boolean isSequential = false;
|
||||
|
||||
if((oldUtf8 != null) && (oldUtf8.length == utf8.length)) {
|
||||
int diffCount = 0;
|
||||
boolean isMoreThanOne = false;
|
||||
boolean nextByteMustIncrement = false;
|
||||
|
||||
for(int index = oldUtf8.length - 1; (!isMoreThanOne) && (index >= 0); index--) {
|
||||
if((nextByteMustIncrement) && ((oldUtf8[index] + 1) != utf8[index])) {
|
||||
isMoreThanOne = true;
|
||||
nextByteMustIncrement = false;
|
||||
}//if//
|
||||
else if(oldUtf8[index] != utf8[index]) {
|
||||
diffCount++;
|
||||
|
||||
if((oldUtf8[index] + 1) != utf8[index]) {
|
||||
if((oldUtf8[index] == 0xFF) && (utf8[index] == 0x00)) {
|
||||
nextByteMustIncrement = true;
|
||||
}//if//
|
||||
else {
|
||||
isMoreThanOne = true;
|
||||
}//else//
|
||||
}//if//
|
||||
}//else if//
|
||||
}//for//
|
||||
|
||||
if((!isMoreThanOne) && (diffCount == 1)) {
|
||||
isSequential = true;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
if(!isSequential) {
|
||||
buffer.append(intValue);
|
||||
buffer.append('\t');
|
||||
buffer.append(StreamSupport.getHexString(unicode16));
|
||||
buffer.append('\t');
|
||||
buffer.append(StreamSupport.getHexString(utf8));
|
||||
buffer.append('\r');
|
||||
buffer.append('\n');
|
||||
|
||||
if(count++ > 1000) {
|
||||
System.out.print(buffer);
|
||||
buffer.setLength(0);
|
||||
//com.common.debug.DebugSupport.halt();
|
||||
count = 0;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
oldUtf8 = utf8;
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
}//printUnicode16ToUTF8HexCodes()//
|
||||
public static void test() {
|
||||
byte[] bytes = null;
|
||||
String str = "abcd\u0aaa\u8488\u0799\uffff";
|
||||
|
||||
//Test the java conversion.//
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
bytes = str.getBytes("UTF8");
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + bytes.length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
//Test the software zealot conversion.//
|
||||
try {
|
||||
SystemManager.setupSystem(new com.common.system.WindowsSystem(), null, null);
|
||||
int length = SystemManager.getUtf8StringLength(str);
|
||||
bytes = new byte[length];
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
com.common.system.SystemManager.convertUtf8StringToBytes(str, bytes, 0);
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
//Test the software zealot conversion.//
|
||||
try {
|
||||
//SystemManager.setupSystem(new com.common.system.WindowsSystem(), null, null);
|
||||
int length = SystemManager.getUtf8StringLength(str);
|
||||
bytes = new byte[length];
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
int strLength = str.length();
|
||||
|
||||
for(int characterIndex = 0; characterIndex < strLength; characterIndex++) {
|
||||
char ch = str.charAt(characterIndex);
|
||||
//byte upper = ch >> 8;
|
||||
//byte lower = ch && 0xFF;
|
||||
|
||||
if(ch == 0) {
|
||||
}//if//
|
||||
else if(ch < 0x7F) {
|
||||
}//else if//
|
||||
else if(ch < 0xFFFF) {
|
||||
}//else if//
|
||||
else {
|
||||
}//else//
|
||||
}//for//
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
}
|
||||
Reference in New Issue
Block a user