이번에 암호화 관련하여 개고생을 한 byte[] ..
byte[] tmp = .....;
Strin strMsg = new String(tmp);
여기서 byte[] 배열을 String 으로 변환하는 new String(byte[]) 생성자에 대해
JDK 1.4 Doc 에 있는 설명을 보면..
The behavior of this constructor when the given bytes are not valid
in the default charset is unspecified.
/**
* Constructs a new <tt>String</tt> by decoding the specified subarray of
* bytes using the platform's default charset. The length of the new
* <tt>String</tt> is a function of the charset, and hence may not be equal
* to the length of the subarray.
*
* <p> The behavior of this constructor when the given bytes are not valid
* in the default charset is unspecified. The {@link
* java.nio.charset.CharsetDecoder} class should be used when more control
* over the decoding process is required.
*
* @param bytes the bytes to be decoded into characters
* @param offset the index of the first byte to decode
* @param length the number of bytes to decode
* @throws IndexOutOfBoundsException
* if the <code>offset</code> and the <code>length</code>
* arguments index characters outside the bounds of the
* <code>bytes</code> array
* @throws NullPointerException
* if <code>bytes</code> array is <code>null</code>
* @since JDK1.1
*/
결국 위 메소드 수행결과는 JDK 버전에 따라 , 플랫폼 별 JDK 에 따라 , 인코딩에 따라 return 되는
결과값에 대해 자바 규약에는 없댄다.. 젠 -_ㅜ
암튼 글의 요지는 byte[] 를 String 으로 변환할때 개조심 하지 않으면 데이타 손실및
통신을 제대로 하고도 데이타를 제대로 구현하지 못한다는 것이다..
아래는 www.javaservice.net 에서 친절하게도 테스트 해준 결과값..
(진작에 찾아 봤으면 개고생 안해도 될텐데 .... 이틀을 삽질하고 찾아보고나선
얼마나 좌절을 했는지.. ㅠ_ㅠ)
==========================================================================================
Big5:false
Big5-HKSCS:false
EUC-CN:false
EUC-JP:false
euc-jp-linux:false
EUC-KR:false
EUC-TW:error
GB18030:false
GBK:false
ISCII91:error
ISO-2022-CN-CNS:error
ISO-2022-CN-GB:error
ISO-2022-KR:error
ISO-8859-1:true
ISO-8859-13:true
ISO-8859-15:true
ISO-8859-2:true
ISO-8859-3:false
ISO-8859-4:true
ISO-8859-5:true
ISO-8859-6:false
ISO-8859-7:false
ISO-8859-8:false
ISO-8859-9:true
JIS0201:false
JIS0208:false
JIS0212:false
Johab:false
KOI8-R:true
Shift_JIS:false
TIS-620:false
US-ASCII:false
UTF-16:false
UTF-16BE:false
UTF-16LE:false
UTF-8:false
windows-1250:false
windows-1251:false
windows-1252:false
windows-1253:false
windows-1254:false
windows-1255:false
windows-1256:true
windows-1257:false
windows-1258:false
windows-936:false
windows-949:false
windows-950:false
==========================================================================================
byte[] tmp = .....;
Strin strMsg = new String(tmp);
여기서 byte[] 배열을 String 으로 변환하는 new String(byte[]) 생성자에 대해
JDK 1.4 Doc 에 있는 설명을 보면..
The behavior of this constructor when the given bytes are not valid
in the default charset is unspecified.
/**
* Constructs a new <tt>String</tt> by decoding the specified subarray of
* bytes using the platform's default charset. The length of the new
* <tt>String</tt> is a function of the charset, and hence may not be equal
* to the length of the subarray.
*
* <p> The behavior of this constructor when the given bytes are not valid
* in the default charset is unspecified. The {@link
* java.nio.charset.CharsetDecoder} class should be used when more control
* over the decoding process is required.
*
* @param bytes the bytes to be decoded into characters
* @param offset the index of the first byte to decode
* @param length the number of bytes to decode
* @throws IndexOutOfBoundsException
* if the <code>offset</code> and the <code>length</code>
* arguments index characters outside the bounds of the
* <code>bytes</code> array
* @throws NullPointerException
* if <code>bytes</code> array is <code>null</code>
* @since JDK1.1
*/
결국 위 메소드 수행결과는 JDK 버전에 따라 , 플랫폼 별 JDK 에 따라 , 인코딩에 따라 return 되는
결과값에 대해 자바 규약에는 없댄다.. 젠 -_ㅜ
암튼 글의 요지는 byte[] 를 String 으로 변환할때 개조심 하지 않으면 데이타 손실및
통신을 제대로 하고도 데이타를 제대로 구현하지 못한다는 것이다..
아래는 www.javaservice.net 에서 친절하게도 테스트 해준 결과값..
(진작에 찾아 봤으면 개고생 안해도 될텐데 .... 이틀을 삽질하고 찾아보고나선
얼마나 좌절을 했는지.. ㅠ_ㅠ)
==========================================================================================
Big5:false
Big5-HKSCS:false
EUC-CN:false
EUC-JP:false
euc-jp-linux:false
EUC-KR:false
EUC-TW:error
GB18030:false
GBK:false
ISCII91:error
ISO-2022-CN-CNS:error
ISO-2022-CN-GB:error
ISO-2022-KR:error
ISO-8859-1:true
ISO-8859-13:true
ISO-8859-15:true
ISO-8859-2:true
ISO-8859-3:false
ISO-8859-4:true
ISO-8859-5:true
ISO-8859-6:false
ISO-8859-7:false
ISO-8859-8:false
ISO-8859-9:true
JIS0201:false
JIS0208:false
JIS0212:false
Johab:false
KOI8-R:true
Shift_JIS:false
TIS-620:false
US-ASCII:false
UTF-16:false
UTF-16BE:false
UTF-16LE:false
UTF-8:false
windows-1250:false
windows-1251:false
windows-1252:false
windows-1253:false
windows-1254:false
windows-1255:false
windows-1256:true
windows-1257:false
windows-1258:false
windows-936:false
windows-949:false
windows-950:false
==========================================================================================
이올린에 북마크하기
이올린에 추천하기



