Java Byte Array to String by Charset getBytesUnchecked(String string, String charsetName)

Here you can find the source of getBytesUnchecked(String string, String charsetName)

Description

get Bytes Unchecked

License

Apache License

Declaration

public static byte[] getBytesUnchecked(String string, String charsetName) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

public class Main {
    public static byte[] getBytesUnchecked(String string, String charsetName) {
        if (string == null) {
            return null;
        } else {// w  ww  . j  av a 2s  .  c  om
            try {
                return string.getBytes(charsetName);
            } catch (UnsupportedEncodingException var3) {
                throw newIllegalStateException(charsetName, var3);
            }
        }
    }

    private static byte[] getBytes(String string, Charset charset) {
        return string == null ? null : string.getBytes(charset);
    }

    private static IllegalStateException newIllegalStateException(String charsetName,
            UnsupportedEncodingException e) {
        return new IllegalStateException(charsetName + ": " + e);
    }
}

Related

  1. getBytes(final char[] data, String charset)
  2. getBytes(final String string, final Charset charset)
  3. getBytes(String string, Charset charset)
  4. getBytesByCharset(String str, Charset charset)
  5. getBytesUnchecked(String string, String charsetName)
  6. getChars(byte[] data, String charset)
  7. getContentAsString(byte[] content, Charset charset)
  8. getMaxBytes(String string, int maxBytes, Charset charSet)
  9. getNumberOfBytesPerCharacter(final String charsetName)