Code example for ByteBuffer

Methods: get, limit

0
		return count;
	} 
 
	private static byte[] encode(String text, Charset charset) {
		ByteBuffer buffer = charset.encode(text);
		byte[] bytes = new byte[buffer.limit()];
		buffer.get(bytes);
		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");
			} 
			if (ch > 0x7f) {