List of utility methods to do Byte Array to String by Charset
String | toString(byte[] data, int from, int length, Charset charset) Convert to string with UTF8 charset. return new String(Arrays.copyOfRange(data, from, from + length), charset); |
String | toString(final byte[] bytes, final String charsetName) Converts a byte[] to a String using the specified character encoding.
return charsetName != null ? new String(bytes, charsetName) : new String(bytes, Charset.defaultCharset()); |
String | toUnicode(byte[] isoStr, String charset) to Unicode return new String(isoStr, Charset.forName(charset)); |
String | truncateByByteLength(String string, int maxBytes, Charset charset) truncate By Byte Length CharsetEncoder ce = charset.newEncoder(); if (string.length() * ce.maxBytesPerChar() <= maxBytes) return string; CharBuffer chars = CharBuffer.wrap(string); ByteBuffer bytes = ByteBuffer.allocate(maxBytes); CoderResult result = ce.encode(chars, bytes, true); return result.isOverflow() ? new String(bytes.array(), 0, bytes.position(), charset) : string; |
List | yaml2List(Charset charset, byte[] data) yaml List List<String> list = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data), charset)); String line = null; while ((line = reader.readLine()) != null) { String[] kvs = line.split(" "); if (kvs.length == 2) { list.add(kvs[1].trim()); return list; |