Code example for CharsetEncoder

Methods: encode

0
 
        ByteBuffer bbuf = null;
        try { 
            // Convert a string to ISO-LATIN-1 bytes in a ByteBuffer 
            // The new ByteBuffer is ready to be read. 
            bbuf = encoder.encode( CharBuffer.wrap( input ) );
 
        } catch ( CharacterCodingException e ) {
            LOG.logError( e.getMessage(), e );
        } 
        return bbuf.toString();
    } 
 
    /** 
     * A method to convert an input string in UTF-8 to a given charset by using {@link java.nio.charset.CharsetDecoder} 
     * @param input 
     * @param targetCharset 
     * @return the decoded string 
     */ 
    public static String convertFromUnicode( String input, String targetCharset ) {
        // Create the encoder and decoder for inCharset