diff options
Diffstat (limited to 'plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java')
-rw-r--r-- | plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java | 103 |
1 files changed, 41 insertions, 62 deletions
diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java index b6150090b..0680467f1 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java @@ -19,87 +19,66 @@ import org.eclipse.tcf.services.IStreams; import org.eclipse.tcf.util.TCFTask; public class TCFTerminalOutputStream extends OutputStream { - + private final TCFTerminalShell terminal; private final IStreams streams; + private final String os_id; private boolean connected = true; - private boolean write_eof; - String os_id; - public TCFTerminalOutputStream(final IStreams streams, final String os_id) throws IOException{ + public TCFTerminalOutputStream(TCFTerminalShell terminal, IStreams streams, String os_id) throws IOException{ if (streams == null) throw new IOException("istream is null");//$NON-NLS-1$ + this.terminal = terminal; this.streams = streams; this.os_id = os_id; - write_eof = false; } @Override public synchronized void write(final byte b[], final int off, final int len) throws IOException { /* If eof is written, we can't write anything into the stream */ - if (!connected || write_eof) - throw new IOException("stream is not connected or write_eof already!");//$NON-NLS-1$ - try { - new TCFTask<Object>() { - public void run() { - streams.write(os_id, b, off, len, new IStreams.DoneWrite() { - public void doneWrite(IToken token, Exception error) { - if (error != null) error(error); - done(this); - } - }); - - } - }.getIO(); - } - catch (Exception e) - { - throw new IOException(e.getMessage());//$NON-NLS-1$ - } + if (!connected) throw new IOException("stream is not connected!");//$NON-NLS-1$ + new TCFTask<Object>() { + public void run() { + streams.write(os_id, b, off, len, new IStreams.DoneWrite() { + public void doneWrite(IToken token, Exception error) { + if (error != null) error(error); + else done(this); + } + }); + } + }.getIO(); } @Override public synchronized void write(int b) throws IOException { - - try { - final byte[] buf = new byte[1]; - buf[0] = (byte)b; - this.write(buf, 0, 1); - } - catch(IOException ioe) { - throw new IOException(ioe.getMessage());//$NON-NLS-1$ - } - + byte[] buf = new byte[1]; + buf[0] = (byte)b; + write(buf, 0, 1); } /* close must be called --Need to reconsider it in the future*/ public void close() throws IOException { - if (!connected) - return; - try { - new TCFTask<Object>() { - public void run() { - streams.eos(os_id, new IStreams.DoneEOS() { - public void doneEOS(IToken token, Exception error) { - write_eof = true; - done(this); - } - }); - } - }.getIO(); - new TCFTask<Object>() { - public void run() { - streams.disconnect(os_id, new IStreams.DoneDisconnect() { - public void doneDisconnect(IToken token, Exception error) { - connected = false; - done(this); + if (!connected) return; + connected = false; + new TCFTask<Object>() { + public void run() { + streams.eos(os_id, new IStreams.DoneEOS() { + public void doneEOS(IToken token, Exception error) { + if (error != null) { + error(error); + return; } - }); - - } - }.getIO(); - } - catch(Exception e) { - throw new IOException(e.getMessage()); //$NON-NLS-1$ - } + streams.disconnect(os_id, new IStreams.DoneDisconnect() { + public void doneDisconnect(IToken token, Exception error) { + if (error != null) { + error(error); + return; + } + terminal.onOutputStreamClosed(); + done(this); + } + }); + } + }); + } + }.getIO(); } - } |