Code example for CharBuffer

Methods: toString

0
 
		// Convert ISO-LATIN-1 bytes in a ByteBuffer to a character 
		// ByteBuffer and then to a string. 
		// The new ByteBuffer is ready to be read. 
		CharBuffer cbuf = decoder.decode(ByteBuffer.wrap(octetstring));
		String s = cbuf.toString();
		return s;
	} 
 
	public static byte[] stringToByteArray(String charset, String valueToEncode) {
		try { 
			return valueToEncode.getBytes(charset);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		} 
	} 
 
}