Code example for CharsetDecoder

Methods: maxCharsPerByteonMalformedInputonUnmappableCharacterreplaceWith

0
            throw msg.parameterOutOfRange("bufferSize"); 
        } 
        this.writer = writer;
        this.decoder = decoder;
        byteBuffer = ByteBuffer.allocate(bufferSize);
        chars = new char[(int) ((float)bufferSize * decoder.maxCharsPerByte() + 0.5f)];
    } 
 
    /** 
     * Construct a new instance. 
     * 
     * @param writer the writer to decode into 
     * @param charset the character set to use 
     */ 
    public WriterOutputStream(final Writer writer, final Charset charset) {
        this(writer, getDecoder(charset));
    } 
 
    /** 
     * Construct a new instance. 
     * 
     * @param writer the writer to decode into 
     * @param charsetName the character set name to use 
     * @throws UnsupportedEncodingException if the character set name is unknown 
     */ 
    public WriterOutputStream(final Writer writer, final String charsetName) throws UnsupportedEncodingException {
        this(writer, Streams.getCharset(charsetName));
    } 
 
    private static CharsetDecoder getDecoder(final Charset charset) {
        final CharsetDecoder decoder = charset.newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPLACE);
        decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
        decoder.replaceWith("?");
        return decoder;
    } 
 
    /** {@inheritDoc} */ 
    public void write(final int b) throws IOException {