package pw.koj.jetstreem.core;

import java.nio.channels.WritableByteChannel;
import java.io.DataOutputStream;
import java.io.IOException;

public class StrmWriteIO extends Streem {
    private DataOutputStream outStream;

    public StrmWriteIO(StrmQueue queue, DataOutputStream outStream) {
        super(TaskMode.CONS, queue, StrmWriteIO::writeCb, StrmWriteIO::writeClose, null);
        this.outStream = outStream;
    }

    public DataOutputStream outStream() {
        return this.outStream;
    }

    public static void writeCb(Streem strm, Object data) {
        StrmWriteIO ioStrm = (StrmWriteIO)strm;
        DataOutputStream out = ioStrm.outStream();
        String str = (String)data;

        try {
            out.writeUTF(str);
        } catch (IOException ex) {
            System.err.println("I/O error: " + ex.getMessage());
        }
    }

    public static void writeClose(Streem strm, Object data) {
        // TBD
    }

}

package pw.koj.jetstreem.core;

import java.nio.channels.WritableByteChannel;
import java.io.PrintStream;

public class StrmWriteIO extends Streem {
    private PrintStream outStream;

    public StrmWriteIO(StrmQueue queue, PrintStream outStream) {
        super(TaskMode.CONS, queue, StrmWriteIO::writeCb, StrmWriteIO::writeClose, null);
        this.outStream = outStream;
    }

    public PrintStream outStream() {
        return this.outStream;
    }

    public static void writeCb(Streem strm, Object data) {
        StrmWriteIO ioStrm = (StrmWriteIO)strm;
        PrintStream out = ioStrm.outStream();

        out.print(data);
    }

    public static void writeClose(Streem strm, Object data) {
        StrmWriteIO s = (StrmWriteIO)strm;
        s.outStream().close();
    }

}

modify writeCb() and implement writeClose() in StrmWriteIO