KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > channel > ChannelOutputStream


1 package ch.ethz.ssh2.channel;
2
3 import java.io.IOException JavaDoc;
4 import java.io.OutputStream JavaDoc;
5
6 /**
7  * ChannelOutputStream.
8  *
9  * @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 JavaDoc
13 {
14     Channel c;
15
16     boolean isClosed = false;
17     
18     ChannelOutputStream(Channel c)
19     {
20         this.c = c;
21     }
22
23     public void write(int b) throws IOException JavaDoc
24     {
25         byte[] buff = new byte[1];
26         
27         buff[0] = (byte) b;
28         
29         write(buff, 0, 1);
30     }
31
32     public void close() throws IOException JavaDoc
33     {
34         if (isClosed == false)
35         {
36             isClosed = true;
37             c.cm.sendEOF(c);
38         }
39     }
40
41     public void flush() throws IOException JavaDoc
42     {
43         if (isClosed)
44             throw new IOException JavaDoc("This OutputStream is closed.");
45
46         /* This is a no-op, since this stream is unbuffered */
47     }
48
49     public void write(byte[] b, int off, int len) throws IOException JavaDoc
50     {
51         if (isClosed)
52             throw new IOException JavaDoc("This OutputStream is closed.");
53         
54         if (b == null)
55             throw new NullPointerException JavaDoc();
56
57         if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length))
58             throw new IndexOutOfBoundsException JavaDoc();
59
60         if (len == 0)
61             return;
62         
63         c.cm.sendData(c, b, off, len);
64     }
65
66     public void write(byte[] b) throws IOException JavaDoc
67     {
68         write(b, 0, b.length);
69     }
70 }
71
Popular Tags