comparison src/com/trilead/ssh2/channel/ChannelOutputStream.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1 package com.trilead.ssh2.channel;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5
6 /**
7 * ChannelOutputStream.
8 *
9 * @author Christian Plattner, plattner@trilead.com
10 * @version $Id: ChannelOutputStream.java,v 1.1 2007/10/15 12:49:56 cplattne Exp $
11 */
12 public final class ChannelOutputStream extends OutputStream {
13 Channel c;
14
15 private byte[] writeBuffer;
16
17 boolean isClosed = false;
18
19 ChannelOutputStream(Channel c) {
20 this.c = c;
21 writeBuffer = new byte[1];
22 }
23
24 public void write(int b) throws IOException {
25 writeBuffer[0] = (byte) b;
26 write(writeBuffer, 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) || ((off + len) < 0) || (off > b.length))
51 throw new IndexOutOfBoundsException();
52
53 if (len == 0)
54 return;
55
56 c.cm.sendData(c, b, off, len);
57 }
58
59 public void write(byte[] b) throws IOException {
60 write(b, 0, b.length);
61 }
62 }