All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.talend.esb.sam.agent.wiretap.WriterOutputStream Maven / Gradle / Ivy

There is a newer version: 8.0.1.R2024-05-RT
Show newest version
package org.talend.esb.sam.agent.wiretap;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;

/**
 *  Wraps a Writer as an OutputStream.
 */
public class WriterOutputStream extends OutputStream {

    private Writer writer;
    private String encoding;
    private byte[] buffer = new byte[1];

    public WriterOutputStream(Writer writer, String encoding) {
        this.writer = writer;
        this.encoding = encoding;
    }

    public void write(byte[] b) throws IOException {
        writer.write(new String(b, encoding));
    }

    public void write(byte[] b, int off, int len) throws IOException {
        writer.write(new String(b, off, len, encoding));
    }

    public synchronized void write(int b) throws IOException {
        buffer[0] = (byte) b;
        write(buffer);
    }

    public void close() throws IOException {
        writer.close();
        writer = null;
        encoding = null;
    }

    public void flush() throws IOException {
        writer.flush();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy