Charset cs = findCharset(encoding);
// can't simply .array() this to get the bytes
// especially with variable-length charsets the
// buffer is sometimes larger than the actual encoded data
ByteBuffer buf = cs.encode(value);
int encodedLen = buf.limit();
byte[] asBytes = new byte[encodedLen];
buf.get(asBytes, 0, encodedLen);