01: package ch.ethz.ssh2.channel;
02:
03: import java.io.IOException;
04: import java.io.OutputStream;
05:
06: /**
07: * ChannelOutputStream.
08: *
09: * @author Christian Plattner, plattner@inf.ethz.ch
10: * @version $Id: ChannelOutputStream.java,v 1.3 2005/08/11 12:47:30 cplattne Exp $
11: */
12: public final class ChannelOutputStream extends OutputStream {
13: Channel c;
14:
15: boolean isClosed = false;
16:
17: ChannelOutputStream(Channel c) {
18: this .c = c;
19: }
20:
21: public void write(int b) throws IOException {
22: byte[] buff = new byte[1];
23:
24: buff[0] = (byte) b;
25:
26: write(buff, 0, 1);
27: }
28:
29: public void close() throws IOException {
30: if (isClosed == false) {
31: isClosed = true;
32: c.cm.sendEOF(c);
33: }
34: }
35:
36: public void flush() throws IOException {
37: if (isClosed)
38: throw new IOException("This OutputStream is closed.");
39:
40: /* This is a no-op, since this stream is unbuffered */
41: }
42:
43: public void write(byte[] b, int off, int len) throws IOException {
44: if (isClosed)
45: throw new IOException("This OutputStream is closed.");
46:
47: if (b == null)
48: throw new NullPointerException();
49:
50: if ((off < 0) || (len < 0) || ((off + len) > b.length)
51: || ((off + len) < 0) || (off > b.length))
52: throw new IndexOutOfBoundsException();
53:
54: if (len == 0)
55: return;
56:
57: c.cm.sendData(c, b, off, len);
58: }
59:
60: public void write(byte[] b) throws IOException {
61: write(b, 0, b.length);
62: }
63: }
|