Here you can find the source of toUTF16LEString(String input)
Parameter | Description |
---|---|
input | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String toUTF16LEString(String input) throws IOException
//package com.java2s; import java.io.IOException; public class Main { /**//w w w . jav a2s. com * Convert the input string to String encoded in UTF16LE format. * * @param input * @return String encoded in UTF16LE format * @throws IOException */ public static String toUTF16LEString(String input) throws IOException { if (input == null || input.length() == 0) { return input; } byte[] b = input.getBytes("UTF-16LE"); return hexToString(b); } /** * Converts a byte array to string. * * @param data * Input byte array. * @return String */ public static String hexToString(byte[] data) { if (data == null) { return ""; } ; StringBuffer sb = new StringBuffer(data.length * 2); for (int i = 0; i < data.length; i++) { String hex = Integer.toHexString(0xFF & data[i]); if (hex.length() == 1) { sb.append('0'); } sb.append(hex); } return sb.toString().toUpperCase(); } /** * Converts object to a string.<br> * If object is null then return null * * @param obj * @return */ public static String toString(Object obj) { if (null == obj) { return null; } else { return obj.toString(); } } }