Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/channel/ChannelInputStream.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.InputStream; | 8 import java.io.InputStream; |
9 | 9 |
10 /** | 10 /** |
11 * ChannelInputStream. | 11 * ChannelInputStream. |
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 ChannelInputStream extends InputStream | 16 public final class ChannelInputStream extends InputStream { |
17 { | 17 Channel c; |
18 Channel c; | |
19 | 18 |
20 boolean isClosed = false; | 19 boolean isClosed = false; |
21 boolean isEOF = false; | 20 boolean isEOF = false; |
22 boolean extendedFlag = false; | 21 boolean extendedFlag = false; |
23 | 22 |
24 ChannelInputStream(Channel c, boolean isExtended) | 23 ChannelInputStream(Channel c, boolean isExtended) { |
25 { | 24 this.c = c; |
26 this.c = c; | 25 this.extendedFlag = isExtended; |
27 this.extendedFlag = isExtended; | 26 } |
28 } | |
29 | 27 |
30 @Override | 28 @Override |
31 public int available() throws IOException | 29 public int available() throws IOException { |
32 { | 30 if (isEOF) |
33 if (isEOF) | 31 return 0; |
34 return 0; | |
35 | 32 |
36 int avail = c.cm.getAvailable(c, extendedFlag); | 33 int avail = c.cm.getAvailable(c, extendedFlag); |
34 /* We must not return -1 on EOF */ | |
35 return (avail > 0) ? avail : 0; | |
36 } | |
37 | 37 |
38 /* We must not return -1 on EOF */ | 38 @Override |
39 public void close() throws IOException { | |
40 isClosed = true; | |
41 } | |
39 | 42 |
40 return (avail > 0) ? avail : 0; | 43 @Override |
41 } | 44 public int read(byte[] b, int off, int len) throws IOException { |
45 if (b == null) | |
46 throw new NullPointerException(); | |
42 | 47 |
43 @Override | 48 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) |
44 public void close() throws IOException | 49 throw new IndexOutOfBoundsException(); |
45 { | |
46 isClosed = true; | |
47 } | |
48 | 50 |
49 @Override | 51 if (len == 0) |
50 public int read(byte[] b, int off, int len) throws IOException | 52 return 0; |
51 { | |
52 if (b == null) | |
53 throw new NullPointerException(); | |
54 | 53 |
55 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) | 54 if (isEOF) |
56 throw new IndexOutOfBoundsException(); | 55 return -1; |
57 | 56 |
58 if (len == 0) | 57 int ret = c.cm.getChannelData(c, extendedFlag, b, off, len); |
59 return 0; | |
60 | 58 |
61 if (isEOF) | 59 if (ret == -1) { |
62 return -1; | 60 isEOF = true; |
61 } | |
63 | 62 |
64 int ret = c.cm.getChannelData(c, extendedFlag, b, off, len); | 63 return ret; |
64 } | |
65 | 65 |
66 if (ret == -1) | 66 @Override |
67 { | 67 public int read(byte[] b) throws IOException { |
68 isEOF = true; | 68 return read(b, 0, b.length); |
69 } | 69 } |
70 | 70 |
71 return ret; | 71 @Override |
72 } | 72 public int read() throws IOException { |
73 /* Yes, this stream is pure and unbuffered, a single byte read() is slow */ | |
74 final byte b[] = new byte[1]; | |
75 int ret = read(b, 0, 1); | |
73 | 76 |
74 @Override | 77 if (ret != 1) |
75 public int read(byte[] b) throws IOException | 78 return -1; |
76 { | |
77 return read(b, 0, b.length); | |
78 } | |
79 | 79 |
80 @Override | 80 return b[0] & 0xff; |
81 public int read() throws IOException | 81 } |
82 { | |
83 /* Yes, this stream is pure and unbuffered, a single byte read() is slow */ | |
84 | |
85 final byte b[] = new byte[1]; | |
86 | |
87 int ret = read(b, 0, 1); | |
88 | |
89 if (ret != 1) | |
90 return -1; | |
91 | |
92 return b[0] & 0xff; | |
93 } | |
94 } | 82 } |