org.apache.http.util.CharsetUtils.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.http.util.CharsetUtils.java

Source

package org.apache.http.util;

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

public class CharsetUtils {
    public static Charset lookup(String str) {
        Charset charset = null;
        if (str != null) {
            try {
                charset = Charset.forName(str);
            } catch (UnsupportedCharsetException e) {
            }
        }
        return charset;
    }

    public static Charset get(String str) throws UnsupportedEncodingException {
        if (str == null) {
            return null;
        }
        try {
            return Charset.forName(str);
        } catch (UnsupportedCharsetException e) {
            throw new UnsupportedEncodingException(str);
        }
    }
}