ByteBufferWriter.java 1.15 KB
Newer Older
1 2 3 4
/**
 * $Revision: $
 * $Date: $
 *
5
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
6 7
 *
 * This software is published under the terms of the GNU Public License (GPL),
8 9
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
10 11
 */

12
package org.jivesoftware.openfire.nio;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

import org.apache.mina.common.ByteBuffer;

import java.io.IOException;
import java.io.Writer;
import java.nio.charset.CharsetEncoder;

/**
 * Wrapper on a MINA {@link ByteBuffer} that extends the Writer class.
 *
 * @author Gaston Dombia
 */
public class ByteBufferWriter extends Writer {
    private CharsetEncoder encoder;
    private ByteBuffer byteBuffer;


    public ByteBufferWriter(ByteBuffer byteBuffer, CharsetEncoder encoder) {
        this.encoder = encoder;
        this.byteBuffer = byteBuffer;
    }

    public void write(char cbuf[], int off, int len) throws IOException {
        byteBuffer.putString(new String(cbuf, off, len), encoder);
    }

    public void flush() throws IOException {
        // Ignore
    }

    public void close() throws IOException {
        // Ignore
    }
}