Code example for Charset

Methods: encode

		return count;
	private static byte[] encode(String text, Charset charset) {
		ByteBuffer buffer = charset.encode(text);
		byte[] bytes = new byte[buffer.limit()];
		return bytes;
	private static Charset determineCharset(String text) {
		// it is an important property of iso-8859-1 that it directly maps 
		// unicode code points 0000 to 00ff to byte values 00 to ff. 
		boolean ascii = true;
		final int len = text.length();
		for (int index = 0; index < len; index++) {
			char ch = text.charAt(index);
			if (ch > 0xff) {
				return Charset.forName("UTF-8");
Contextual code suggestions in your IDE  Get Codota for Java