List of utility methods to do Byte Array to String by Charset
boolean | identify(byte[] bytes, CharsetDecoder decoder) identify try { decoder.decode(ByteBuffer.wrap(bytes)); } catch (CharacterCodingException e) { return false; return true; |
String | inflate(byte[] bytes, Charset encoding) inflate Inflater inf = new Inflater(true); inf.reset(); inf.setInput(bytes); byte[] buffer = getThreadBuffer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); while (!inf.finished()) { int n = inf.inflate(buffer); baos.write(buffer, 0, n); ... |
boolean | isCharset(byte[] b, String inCharset) is Charset CharsetDecoder cd = Charset.availableCharsets().get(inCharset).newDecoder(); try { cd.decode(ByteBuffer.wrap(b)); } catch (CharacterCodingException e) { return false; return true; |
String | newString(byte[] bytes, Charset charset) new String return bytes == null ? null : new String(bytes, charset); |
String | newString(byte[] bytes, String charsetName) Constructs a new String by decoding the specified array of bytes using the given charset.
if (bytes == null) { return null; try { return new String(bytes, charsetName); } catch (Exception e) { return null; ... |
String | newString(final byte[] bytes, final Charset charset) new String return bytes == null ? null : new String(bytes, charset); |
String | newString(final byte[] bytes, final Charset charset) Constructs a new String by decoding the specified array of bytes using the given charset.
return bytes == null ? null : new String(bytes, charset); |
String | newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length) new String From Split ByteBuffer fieldBuf = ByteBuffer.wrap(fieldBytes, 0, length); CharBuffer fieldCharBuf = CharBuffer.allocate(length); utf8Decoder.reset(); CoderResult res = utf8Decoder.decode(fieldBuf, fieldCharBuf, true); if (res.isError() && decoder != null) { decoder.reset(); res = decoder.decode(fieldBuf, fieldCharBuf, true); if (!res.isError()) { ... |
String | parseBytes(byte[] encoded, Charset charset) parse Bytes String decoded = new String(encoded, charset.name()); return decoded; |
String | str(byte[] bytes, String charset) str return new String(bytes, Charset.forName(charset)); |