1 package ch.ethz.ssh2.channel; 2 3 import java.io.IOException ; 4 import java.io.OutputStream ; 5 6 12 public final class ChannelOutputStream extends OutputStream 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 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 33 { 34 if (isClosed == false) 35 { 36 isClosed = true; 37 c.cm.sendEOF(c); 38 } 39 } 40 41 public void flush() throws IOException 42 { 43 if (isClosed) 44 throw new IOException ("This OutputStream is closed."); 45 46 47 } 48 49 public void write(byte[] b, int off, int len) throws IOException 50 { 51 if (isClosed) 52 throw new IOException ("This OutputStream is closed."); 53 54 if (b == null) 55 throw new NullPointerException (); 56 57 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) 58 throw new IndexOutOfBoundsException (); 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 67 { 68 write(b, 0, b.length); 69 } 70 } 71 | Popular Tags |