-
Bug
-
Resolution: Fixed
-
P3
-
6
-
None
-
b25
-
generic
-
generic
The self-explanatory program below should not throw an exception
---------------------------------------------------------------------
import java.nio.*;
import java.nio.charset.*;
class Reset {
public static void main(String[] args) throws Exception {
if (! (encode(true).equals(encode(false))))
throw new Exception("Mismatch!");
}
static String encode(boolean reuseEncoder) {
String s = "\u3042\u3043\u3044";
CharsetEncoder e = Charset.forName("ISO-2022-JP").newEncoder();
if (reuseEncoder) {
// I'm turning japanese. Yes I'm turning japanese. Yes I think so!
e.encode(CharBuffer.wrap(s), ByteBuffer.allocate(64), true);
// Should put encoder back into ASCII mode
e.reset();
}
ByteBuffer bb = ByteBuffer.allocate(64);
e.encode(CharBuffer.wrap(s), bb, true);
e.flush(bb);
bb.flip();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bb.limit(); i++)
sb.append(String.format("%02x ", bb.get(i)));
System.out.println(sb);
return sb.toString();
}
}
---------------------------------------------------------------------
###@###.### 2005-2-08 03:13:25 GMT
---------------------------------------------------------------------
import java.nio.*;
import java.nio.charset.*;
class Reset {
public static void main(String[] args) throws Exception {
if (! (encode(true).equals(encode(false))))
throw new Exception("Mismatch!");
}
static String encode(boolean reuseEncoder) {
String s = "\u3042\u3043\u3044";
CharsetEncoder e = Charset.forName("ISO-2022-JP").newEncoder();
if (reuseEncoder) {
// I'm turning japanese. Yes I'm turning japanese. Yes I think so!
e.encode(CharBuffer.wrap(s), ByteBuffer.allocate(64), true);
// Should put encoder back into ASCII mode
e.reset();
}
ByteBuffer bb = ByteBuffer.allocate(64);
e.encode(CharBuffer.wrap(s), bb, true);
e.flush(bb);
bb.flip();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bb.limit(); i++)
sb.append(String.format("%02x ", bb.get(i)));
System.out.println(sb);
return sb.toString();
}
}
---------------------------------------------------------------------
###@###.### 2005-2-08 03:13:25 GMT
- relates to
-
JDK-6211145 ISO-2022-JP encoder doesn't output tail escape sequence
-
- Closed
-