Here you can find the source of bytes2StringUNICODE(byte[] buf, int offset, int length, boolean bigEndian)
Parameter | Description |
---|---|
buf | a parameter |
bigEndian | a parameter |
public static String bytes2StringUNICODE(byte[] buf, int offset, int length, boolean bigEndian)
//package com.java2s; public class Main { /**/*from www .j av a 2 s . com*/ * format the byte[] to String in UNICODE encode * @param buf * @param bigEndian * @return */ public static String bytes2StringUNICODE(byte[] buf, int offset, int length, boolean bigEndian) { if (buf != null && offset >= 0 && length >= 2 && buf.length >= (offset + length)) { int charsLen = length / 2; char[] cbuf = new char[charsLen]; for (int i = 0; i < charsLen; i++) { if (bigEndian) { cbuf[i] = (char) (((buf[i * 2 + offset] & 0xff) << 8 | (buf[i * 2 + 1 + offset] & 0xff)) & 0xffff); } else { cbuf[i] = (char) (((buf[i * 2 + 1 + offset] & 0xff) << 8 | (buf[i * 2 + offset] & 0xff)) & 0xffff); } } String str = new String(cbuf, 0, charsLen); cbuf = null; return str; } return null; } }