projects
/
IRC.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
*** empty log message ***
[IRC.git]
/
Robust
/
src
/
ClassLibrary
/
SocketInputStream.java
1
public class SocketInputStream extends InputStream {
2
Socket s;
3
public SocketInputStream(Socket s) {
4
this.s=s;
5
}
6
7
public int read() {
8
byte[] x=new byte[1];
9
int len=s.read(x);
10
if (len<=0)
11
return -1;
12
else return x[0];
13
}
14
15
public int read(byte[] b) {
16
return s.read(b);
17
}
18
19
public int readAll(byte[] b) {
20
int offset=read(b);
21
if (offset<0)
22
return offset;
23
int toread=b.length-offset;
24
while(toread>0) {
25
byte[] t=new byte[toread];
26
int rd=read(t);
27
if (rd<0)
28
return rd;
29
for(int i=0; i<rd; i++)
30
b[i+offset]=t[i];
31
offset+=rd;
32
toread-=rd;
33
}
34
return b.length;
35
}
36
37
public void close() {
38
s.close();
39
}
40
}