src/main/java/com/rockagen/commons/util/CharsetUtil.java
public static CharsetEncoder getEncoder(Charset charset) {
        if (charset == null) {
            throw new NullPointerException("charset");
        }

        Map<Charset, CharsetEncoder> map = encoders.get();
        CharsetEncoder e = map.get(charset);
        if (e != null) {
            e.reset();
            e.onMalformedInput(CodingErrorAction.REPLACE);
            e.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return e;
        }

        e = charset.newEncoder();
        e.onMalformedInput(CodingErrorAction.REPLACE);
        e.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, e);
        return e;
    }
public static CharsetEncoder getEncoder(Charset charset) {
        if (charset == null) {
            throw new NullPointerException("charset");
        }

        Map<Charset, CharsetEncoder> map = encoders.get();
        CharsetEncoder e = map.get(charset);
        if (e != null) {
            e.reset();
            e.onMalformedInput(CodingErrorAction.REPLACE);
            e.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return e;
        }

        e = charset.newEncoder();
        e.onMalformedInput(CodingErrorAction.REPLACE);
        e.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, e);
        return e;
    }
public static CharsetEncoder getEncoder ( Charset charset ) { if ( charset == null ) { throw new NullPointerException ( "charset" ) ; } Map < Charset , CharsetEncoder > map = encoders . get ( ) ; CharsetEncoder e = map . get ( charset ) ; if ( e != null ) { e . reset ( ) ; e . onMalformedInput ( CodingErrorAction . REPLACE ) ; e . onUnmappableCharacter ( CodingErrorAction . REPLACE ) ; return e ; } e = charset . newEncoder ( ) ; e . onMalformedInput ( CodingErrorAction . REPLACE ) ; e . onUnmappableCharacter ( CodingErrorAction . REPLACE ) ; map . put ( charset , e ) ; return e ; }
Returns a cached thread-local {@link CharsetEncoder} for the specified <tt>charset</tt>.
@param charset {@link java.nio.charset.Charset}
@return {@link java.nio.charset.CharsetEncoder}
Returns a cached thread - local {