ASF Bugzilla – Attachment 5765 Details for
Bug 18846
[PATCH][RFE]Refactor the transformation between byte array and String object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Sample to show that System Encoder/Decoder works like StringUtil want to do.Please execute main and see console.
TestChar.java (text/plain), 2.82 KB, created by
Toshiaki Kamoshida
on 2003-04-10 09:18:05 UTC
(
hide
)
Description:
Sample to show that System Encoder/Decoder works like StringUtil want to do.Please execute main and see console.
Filename:
MIME Type:
Creator:
Toshiaki Kamoshida
Created:
2003-04-10 09:18:05 UTC
Size:
2.82 KB
patch
obsolete
> > >/** > * @author T.Kamoshida > */ >public class TestChar { > > public static void main(String[] args) throws Exception{ > > String unicodestr ="\u0102\u0304\u0506\u0708"; > //as a decoded string with 4chars UNCOMPRESSED UNICODE > String asciistr ="\u0001\u0002\u0003\u0004"; > //as a decoded string with 4chars COMPRESSED UNICODE > > //Show How works each Encoder. > //It shows System Encoder do same job as StringUtil > System.out.println("CASE1:encode String -> byte array with UTF16-BE"); > showEncodeString(unicodestr,"UTF-16BE"); > System.out.println(); > > System.out.println("CASE2:encode String -> byte array with UTF16-LE"); > showEncodeString(unicodestr,"UTF-16LE"); > System.out.println(); > > System.out.println("CASE3:encode String -> byte array with ISO-8859-1"); > showEncodeString(asciistr,"ISO-8859-1"); > System.out.println(); > > //Emulate encoding 16Bit Unicode on Excel File > System.out.println("CASE4:decode byte array 16BitUnicode with LittleEndian(16BitUnicode on XLS)<-> String with UTF-16LE"); > showDecodeString(unicodestr,"UTF-16LE","UTF-16LE"); > System.out.println(); > > //Emulate encoding 8Bit(Compressed)Unicode on Excel File > System.out.println("CASE5:decode byte array Latin1(8Bit compressed Unicode on XLS)<-> String with ISO-8859-1"); > showDecodeString(asciistr,"ISO-8859-1","ISO-8859-1"); > System.out.println(); > > //Emulate mismatch between Decoder and byte array > //please change from "UTF-16" to any "native" encoding indicator > System.out.println("CASE6:To see what happen in the bug in other platform"); > showDecodeString(asciistr,"ISO-8859-1","UTF-16"); > System.out.println(); > showDecodeString(asciistr,"UTF-16","ISO-8859-1"); > System.out.println(); > > System.out.println("CASE7:To see side effect of UTF-16(add endian indicator)"); > showDecodeString(unicodestr,"UTF-16","UTF-16"); > System.out.println(); > showDecodeString(unicodestr,"UTF-16","UTF-16BE"); > System.out.println(); > } > > private static void showChars(String src){ > System.out.print("CHAR SEQUENCE:"); > for(int i = 0 ; i < src.length() ; i++){ > System.out.print("[U+"+Integer.toHexString(src.charAt(i))+"]"); > } > System.out.println(); > } > > > private static byte[] showEncodeString(String src,String dec)throws Exception{ > System.out.println("Base String is:"); > showChars(src); > > System.out.println("Encoder is "+ dec +":"); > byte[] array = src.getBytes(dec); > System.out.print("BYTE ARRAY:"); > for(int i = 0 ; i < array.length ; i++){ > System.out.print("["+Integer.toHexString(array[i] & 0xFF)+"]"); > } > System.out.println(); > return array; > } > > private static void showDecodeString(String src,String dec,String enc)throws Exception{ > byte[] array = showEncodeString(src,dec); > > System.out.println("Decoder is "+ enc +":"); > showChars(new String(array,enc)); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 18846
: 5765 |
6270