//# 0 errors, 39 messages
//#
/*
    //#StringTranscoder.java:1:1: class: com.dmdirc.util.StringTranscoder
    //#StringTranscoder.java:1:1: method: com.dmdirc.util.StringTranscoder.com.dmdirc.util.StringTranscoder__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.util;

import java.nio.charset.Charset;

/**
 * Facilitates easy transcoding of strings.
 * 
 * @author Chris
 */
public class StringTranscoder {
   
    /** The charset that is used by this transcoder. */
    private final Charset charset;
    
    /**
     * Creates a new StringTranscoder that will transcode strings from the
     * system's default character set into the specified charset.
     * 
     * @param charset The target character set
     */
    public StringTranscoder(final Charset charset) {
    //#StringTranscoder.java:43: method: void com.dmdirc.util.StringTranscoder.com.dmdirc.util.StringTranscoder(Charset)
    //#input(void com.dmdirc.util.StringTranscoder(Charset)): charset
    //#input(void com.dmdirc.util.StringTranscoder(Charset)): this
    //#output(void com.dmdirc.util.StringTranscoder(Charset)): this.charset
    //#post(void com.dmdirc.util.StringTranscoder(Charset)): this.charset == charset
    //#post(void com.dmdirc.util.StringTranscoder(Charset)): init'ed(this.charset)
        this.charset = charset;
    }
    //#StringTranscoder.java:45: end of method: void com.dmdirc.util.StringTranscoder.com.dmdirc.util.StringTranscoder(Charset)
    
    /**
     * Transcodes the specified string from the system's default charset to
     * this transcoder's charset.
     * 
     * @param string The string to be transcoded
     * @return A new string of the appropriate charset
     */
    public String encode(final String string) {
        return new String(string.getBytes(charset));
    //#StringTranscoder.java:55: method: String com.dmdirc.util.StringTranscoder.encode(String)
    //#input(String encode(String)): string
    //#input(String encode(String)): this
    //#input(String encode(String)): this.charset
    //#output(String encode(String)): new String(encode#1) num objects
    //#output(String encode(String)): return_value
    //#new obj(String encode(String)): new String(encode#1)
    //#pre[1] (String encode(String)): string != null
    //#post(String encode(String)): return_value == &new String(encode#1)
    //#post(String encode(String)): new String(encode#1) num objects == 1
    //#StringTranscoder.java:55: end of method: String com.dmdirc.util.StringTranscoder.encode(String)
    }
    
    /**
     * Transcodes the specified string from this transcoder's charset to the
     * system's default charset
     * 
     * @param string The string to be transcoded
     * @return A new string of the appropriate charset
     */
    public String decode(final String string) {
        return new String(string.getBytes(), charset);
    //#StringTranscoder.java:66: method: String com.dmdirc.util.StringTranscoder.decode(String)
    //#input(String decode(String)): string
    //#input(String decode(String)): this
    //#input(String decode(String)): this.charset
    //#output(String decode(String)): new String(decode#1) num objects
    //#output(String decode(String)): return_value
    //#new obj(String decode(String)): new String(decode#1)
    //#pre[1] (String decode(String)): string != null
    //#post(String decode(String)): return_value == &new String(decode#1)
    //#post(String decode(String)): new String(decode#1) num objects == 1
    //#StringTranscoder.java:66: end of method: String com.dmdirc.util.StringTranscoder.decode(String)
    }    
    
}
    //#output(com.dmdirc.util.StringTranscoder__static_init): __Descendant_Table[com/dmdirc/util/StringTranscoder]
    //#output(com.dmdirc.util.StringTranscoder__static_init): __Dispatch_Table.decode(Ljava/lang/String;)Ljava/lang/String;
    //#output(com.dmdirc.util.StringTranscoder__static_init): __Dispatch_Table.encode(Ljava/lang/String;)Ljava/lang/String;
    //#post(com.dmdirc.util.StringTranscoder__static_init): __Descendant_Table[com/dmdirc/util/StringTranscoder] == &__Dispatch_Table
    //#post(com.dmdirc.util.StringTranscoder__static_init): __Dispatch_Table.decode(Ljava/lang/String;)Ljava/lang/String; == &decode
    //#post(com.dmdirc.util.StringTranscoder__static_init): __Dispatch_Table.encode(Ljava/lang/String;)Ljava/lang/String; == &encode
    //#StringTranscoder.java:: end of method: com.dmdirc.util.StringTranscoder.com.dmdirc.util.StringTranscoder__static_init
    //#StringTranscoder.java:: end of class: com.dmdirc.util.StringTranscoder
