Code example for Charset

Methods: encode

0
		return toByteArray(array, Charset.defaultCharset());
	} 
 
	public static byte[] toByteArray(char[] array, Charset charset) {
		CharBuffer cbuf = CharBuffer.wrap(array);
		ByteBuffer bbuf = charset.encode(cbuf);
		return bbuf.array();
	} 
	 
	public static String ByteArrayToString(byte[] bytes) {
		return new String(bytes);
	} 
	 
	public static int toInt( byte[] bytes ) {
	    int result = 0;
	    for (int i=0; i<4; i++) {
	      result = ( result << 8 ) - Byte.MIN_VALUE + (int) bytes[i];
	    } 
	    return result;
	  } 
}