...
This compliant solution uses the CharsetEncoder
and CharsetDecoder
classes to handle encoding conversions.
Code Block | ||||
---|---|---|---|---|
| ||||
public static byte[] toCodePage(String charset, String string)
throws IOException {
Charset cs = Charset.forName(charset);
CharsetEncoder coder = cs.newEncoder();
ByteBuffer bytebuf = coder.encode(CharBuffer.wrap(string));
byte[] bytes = new byte[bytebuf.limit()];
bytebuf.get(bytes);
return bytes;
}
|
Noncompliant Code Example
...