Utility method to get ISO english encoded bytes from the input string.

@param data
@return byte[]
976033
static public byte[] getEnglishBytes(String data) {
        if (null == data) {
            return null;
        }
        char[] chars = data.toCharArray();
        byte[] bytes = new byte[chars.length];
        for (int i = 0; i < chars.length; i++) {
            bytes[i] = (byte) chars[i];
        }
        return bytes;
    }
1018610
function decode(data) {

    var languageCodeLength = (data[0] & 0x3F), // 6 LSBs
        languageCode = data.slice(1, 1 + languageCodeLength),
        utf16 = (data[0] & 0x80) !== 0; // assuming UTF-16BE

    // TODO need to deal with UTF in the future
    // console.log("lang " + languageCode + (utf16 ? " utf16" : " utf8"));

    return util.bytesToString(data.slice(languageCodeLength + 1));
}
33172
public static byte[] invert(final byte[] data)	{
		for (int i = data.length; --i >= 0;) {
			data[i] = (byte)~data[i];
		}
		return data;
	}
206650
static public String getEnglishString(byte[] data, int start, int end) {
        int len = end - start;
        if (0 >= len || null == data) {
            return null;
        }
        char chars[] = new char[len];
        for (int i = start; i < end; i++) {
            chars[i] = (char) (data[i] & 0xff);
        }
        return new String(chars);
    }
236820
protected String getString(byte[] data, int offset) {
        if (offset < 0) {
            return "";
        }

        int i = offset;
        while (data[i++] != 0x00) {
            ;
        }
        return getString(data, offset, i - offset - 1);
    }
751040
public static Map<String, Object> parseData(String data) {
		Map<String, Object> ret = new HashMap<String, Object>();
		String[] split = data.split("&");
		for (String s : split) {
			int idx = s.indexOf('=');
			try {
				if (idx != -1) {
					ret.put(URLDecoder.decode(s.substring(0, idx), "UTF-8"), URLDecoder.decode(s.substring(idx + 1), "UTF-8"));
				} else {
					ret.put(URLDecoder.decode(s, "UTF-8"), "true");
				}
			} catch (UnsupportedEncodingException e) {
				// Why.
			}
		}
		return ret;
	}
800239
public static byte[] longToByteArrayBE( long data ) {
        return new byte[]{(byte) ((data >> 56) & 0xff), (byte) ((data >> 48) & 0xff), (byte) ((data >> 40) & 0xff),
                (byte) ((data >> 32) & 0xff), (byte) ((data >> 24) & 0xff), (byte) ((data >> 16) & 0xff),
                (byte) ((data >> 8) & 0xff), (byte) ((data >> 0) & 0xff),};
    }
333567
public static final String getString(byte[] data, int offset)
   {
      return getString(data, offset, data.length - offset);
   }
174518
public static byte[] decodeHex(final String data) {

        checkNotNull("data", data);

        final int len = data.length();

        if ((len & 0x01) != 0) {
            throw new RuntimeException("Odd number of characters.");
        }

        final byte[] out = new byte[len >> 1];

        // two characters form the hex value.
        for (int i = 0, j = 0; j < len; i++) {
            int f = toDigit(data.charAt(j), j) << 4;
            j++;
            f = f | toDigit(data.charAt(j), j);
            j++;
            out[i] = (byte) (f & 0xFF);
        }

        return out;
    }
993185
function extractUnicodeValues( $data )
    {
        $type = $data['type'];
        if ( $type == 'string' )
        {
            return $this->ISOUnicodeCodec->convertString( $data['value'] );
        }
        else if ( $type == 'ascii' )
        {
            return array( $data['value'] );
        }
        else if ( $type == 'unicode' )
        {
            return array( $data['value'] );
        }
        else if ( $type == 'remove' )
        {
            return array( false );
        }
        else if ( $type == 'keep' )
        {
            return array( true );
        }
        return array();
    }
684754
static public byte[] getBytes(StringBuffer data) {
        if (null == data) {
            return null;
        }
        int len = data.length();
        char[] chars = new char[len];
        data.getChars(0, len, chars, 0);
        byte[] bytes = new byte[len];
        for (int i = 0; i < len; i++) {
            bytes[i] = (byte) chars[i];
        }
        return bytes;
    }
292090
public static function utf8Encode($data) {
		if (is_string($data)) {
			return utf8_encode($data);

		} else if (is_array($data)) {
			foreach ($data as $key => $value) {
				$data[utf8_encode($key)] = self::utf8Encode($value);
			}

		} else if (is_object($data)) {
			foreach ($data as $key => $value) {
				$data->{$key} = self::utf8Encode($value);
			}
		}

		return $data;
	}
607986
public static String sm3X16Str(String data, String encoding) {
		byte[] bytes = sm3(data, encoding);
		StringBuilder sm3StrBuff = new StringBuilder();
		for (int i = 0; i < bytes.length; i++) {
			if (Integer.toHexString(0xFF & bytes[i]).length() == 1) {
				sm3StrBuff.append("0").append(
						Integer.toHexString(0xFF & bytes[i]));
			} else {
				sm3StrBuff.append(Integer.toHexString(0xFF & bytes[i]));
			}
		}
		return sm3StrBuff.toString();
	}
805359
public static function decodeMimeStringPart(&$data)
    {
        array_shift($data);
        $encode = strtoupper(array_shift($data));
        $type = strtoupper(array_shift($data));
        if ($type === '') {
            return [];
        }

        $str = array_shift($data);

        return [
            $encode => [
                $type => $str
            ]
        ];
    }
9809
public static Datagram decode(final byte[] data,
                                  boolean allowErr) throws IllegalRequestException {
        try {
            if (log.isDebugEnabled()) {
                log.debug("要解析的数据为：{}", Arrays.toString(data));
            }
            // 字符集数据
            int end = Datagram.CHARSET_OFFSET;
            for (int i = 0; i < Datagram.CHARSET_MAX; end += i, i++) {
                if (data[end] == 0) {
                    break;
                }
            }
            // 字符集
            final String charset = new String(data, Datagram.CHARSET_OFFSET,
                end - Datagram.CHARSET_OFFSET);
            // 版本号
            final byte version = data[Datagram.VERSION_INDEX];
            // 数据报数据类型
            final byte type = data[Datagram.TYPE_INDEX];
            // 长度
            final int len = readLen(data);
            log.debug("要解析的数据报的字符集为：{}，版本号为：{}，数据报类型为：{}", charset, version, type);

            byte[] buffer;
            if ((data.length - Datagram.HEADER_LEN) > len) {
                log.warn("数据报head中的长度字段为：{}，数据报body的实际长度为：{}", len,
                    data.length - Datagram.HEADER_LEN);
                if (allowErr) {
                    buffer = new byte[len + Datagram.HEADER_LEN];
                    System.arraycopy(data, 0, buffer, 0, buffer.length);
                } else {
                    throw new IllegalDataException("数据报head中的长度字段为：" + len + "，数据报body的实际长度为："
                                                   + (data.length - Datagram.HEADER_LEN));
                }
            } else if ((data.length - Datagram.HEADER_LEN) < len) {
                log.error("数据报head中的长度字段为：{}，数据报body的实际长度为：{}", len,
                    data.length - Datagram.HEADER_LEN);
                throw new IllegalDataException("数据报head中的长度字段为：" + len + "，数据报body的实际长度为："
                                               + (data.length - Datagram.HEADER_LEN));
            } else {
                buffer = data;
            }

            log.debug("获取id字段");
            byte[] idByte = new byte[40];
            System.arraycopy(data, 16, idByte, 0, idByte.length);
            String id = new String(idByte);
            log.debug("数据报ID为：{}", id);

            // 有可能是空报文的数据报
            Datagram datagram;
            if (len == 0) {
                log.debug("要解析的数据中head标志body长度为0，直接返回一个空body的datagram对象");
                datagram = new Datagram(buffer, len, null, version, charset, type, idByte);
            } else {
                // 真实的业务数据
                byte[] body = new byte[len];
                System.arraycopy(buffer, Datagram.HEADER_LEN, body, 0, body.length);
                datagram = new Datagram(buffer, len, body, version, charset, type, idByte);
            }
            if (log.isDebugEnabled()) {
                log.debug("封装好的数据报body为：{}", datagram);
            }
            return datagram;
        } catch (Exception e) {
            log.error("数据报解析错误，错误原因：{}", e);
            throw new IllegalRequestException(e);
        }
    }
871031
public byte[] digest(String data, String charset) {
		return digest(StrUtil.bytes(data, charset));
	}
891888
public static byte[] decodeBase64(String encodedData) {
		BufferedReader reader = new BufferedReader(new StringReader(encodedData));
		int length = encodedData.length();
		byte[] retval = new byte[length];
		int actualLength = 0;

		String line;
		try {
			while ((line = reader.readLine()) != null) {
				byte[] rawData = line.getBytes();


				int n = 0;
				for (int i = 0; i < rawData.length; i += 4) {
					n = (base64Chars.indexOf(rawData[i]) << 18) |
							(base64Chars.indexOf(rawData[i + 1]) << 12);

					retval[actualLength++] = (byte) ((n >>> 16) & 255);

					if (rawData[i + 2] != '=') {
						n |= (base64Chars.indexOf(rawData[i + 2]) << 6);
						retval[actualLength++] = (byte) ((n >>> 8) & 255);
					}
					if (rawData[i + 3] != '=') {
						n |= (base64Chars.indexOf(rawData[i + 3]));
						retval[actualLength++] = (byte) (n & 255);
					}
				}
			}
		}
		catch (IOException ioe) {
			throw new IllegalStateException("exception while reading input with message: " + ioe);
		}
		if (actualLength != length) {
			byte[] actualRetval = new byte[actualLength];
			System.arraycopy(retval, 0, actualRetval, 0, actualLength);
			return actualRetval;
		}
		return retval;
	}