Java Byte Array to String by Charset identify(byte[] bytes, CharsetDecoder decoder)

Here you can find the source of identify(byte[] bytes, CharsetDecoder decoder)

Description

identify

License

Open Source License

Declaration

private static boolean identify(byte[] bytes, CharsetDecoder decoder) 

Method Source Code

//package com.java2s;
/*/*from ww w.  jav  a 2 s . c om*/
 * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
 */

import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;

import java.nio.charset.CharsetDecoder;

public class Main {
    private static boolean identify(byte[] bytes, CharsetDecoder decoder) {
        try {
            decoder.decode(ByteBuffer.wrap(bytes));
        } catch (CharacterCodingException e) {
            return false;
        }
        return true;
    }
}

Related

  1. getPrefixWithMaxBytes(String string, int maxBytes, Charset charSet)
  2. getRowId(final byte[] rowId, final Charset charset, final boolean base64encodeValues)
  3. getString(@Nonnull byte[] b, @Nonnegative int bufferSize, @Nonnegative int offset, @Nonnull Charset charset)
  4. getString(byte[] bytes, String charset)
  5. getString(byte[] bytesIn, Charset cs)
  6. inflate(byte[] bytes, Charset encoding)
  7. isCharset(byte[] b, String inCharset)
  8. newString(byte[] bytes, Charset charset)
  9. newString(byte[] bytes, String charsetName)