Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/channel/ChannelOutputStream.java @ 308:42b15aaa7ac7 ganymed
merge
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:21:50 -0700 |
parents | 071eccdff8ea |
children |
comparison
equal
deleted
inserted
replaced
306:90e47d99ea54 | 308:42b15aaa7ac7 |
---|---|
7 import java.io.IOException; | 7 import java.io.IOException; |
8 import java.io.OutputStream; | 8 import java.io.OutputStream; |
9 | 9 |
10 /** | 10 /** |
11 * ChannelOutputStream. | 11 * ChannelOutputStream. |
12 * | 12 * |
13 * @author Christian Plattner | 13 * @author Christian Plattner |
14 * @version 2.50, 03/15/10 | 14 * @version 2.50, 03/15/10 |
15 */ | 15 */ |
16 public final class ChannelOutputStream extends OutputStream | 16 public final class ChannelOutputStream extends OutputStream { |
17 { | 17 Channel c; |
18 Channel c; | |
19 | 18 |
20 boolean isClosed = false; | 19 boolean isClosed = false; |
21 | |
22 ChannelOutputStream(Channel c) | |
23 { | |
24 this.c = c; | |
25 } | |
26 | 20 |
27 @Override | 21 ChannelOutputStream(Channel c) { |
28 public void write(int b) throws IOException | 22 this.c = c; |
29 { | 23 } |
30 byte[] buff = new byte[1]; | |
31 | |
32 buff[0] = (byte) b; | |
33 | |
34 write(buff, 0, 1); | |
35 } | |
36 | 24 |
37 @Override | 25 @Override |
38 public void close() throws IOException | 26 public void write(int b) throws IOException { |
39 { | 27 byte[] buff = new byte[1]; |
40 if (isClosed == false) | 28 buff[0] = (byte) b; |
41 { | 29 write(buff, 0, 1); |
42 isClosed = true; | 30 } |
43 c.cm.sendEOF(c); | |
44 } | |
45 } | |
46 | 31 |
47 @Override | 32 @Override |
48 public void flush() throws IOException | 33 public void close() throws IOException { |
49 { | 34 if (isClosed == false) { |
50 if (isClosed) | 35 isClosed = true; |
51 throw new IOException("This OutputStream is closed."); | 36 c.cm.sendEOF(c); |
37 } | |
38 } | |
52 | 39 |
53 /* This is a no-op, since this stream is unbuffered */ | 40 @Override |
54 } | 41 public void flush() throws IOException { |
42 if (isClosed) | |
43 throw new IOException("This OutputStream is closed."); | |
55 | 44 |
56 @Override | 45 /* This is a no-op, since this stream is unbuffered */ |
57 public void write(byte[] b, int off, int len) throws IOException | 46 } |
58 { | |
59 if (isClosed) | |
60 throw new IOException("This OutputStream is closed."); | |
61 | |
62 if (b == null) | |
63 throw new NullPointerException(); | |
64 | 47 |
65 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) | 48 @Override |
66 throw new IndexOutOfBoundsException(); | 49 public void write(byte[] b, int off, int len) throws IOException { |
50 if (isClosed) | |
51 throw new IOException("This OutputStream is closed."); | |
67 | 52 |
68 if (len == 0) | 53 if (b == null) |
69 return; | 54 throw new NullPointerException(); |
70 | |
71 c.cm.sendData(c, b, off, len); | |
72 } | |
73 | 55 |
74 @Override | 56 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) |
75 public void write(byte[] b) throws IOException | 57 throw new IndexOutOfBoundsException(); |
76 { | 58 |
77 write(b, 0, b.length); | 59 if (len == 0) |
78 } | 60 return; |
61 | |
62 c.cm.sendData(c, b, off, len); | |
63 } | |
64 | |
65 @Override | |
66 public void write(byte[] b) throws IOException { | |
67 write(b, 0, b.length); | |
68 } | |
79 } | 69 } |