01: package pygmy.core;
02:
03: import java.io.PushbackInputStream;
04: import java.io.InputStream;
05: import java.io.IOException;
06:
07: public class InternetInputStream extends PushbackInputStream {
08:
09: public InternetInputStream(InputStream in, int size) {
10: super (in, size);
11: }
12:
13: public InternetInputStream(InputStream in) {
14: super (in, 4096);
15: }
16:
17: public String readline() throws IOException {
18: StringBuffer buf = readBuffer();
19: if (buf == null)
20: return null;
21: return buf.toString();
22: }
23:
24: public StringBuffer readBuffer() throws IOException {
25: StringBuffer buffer = null;
26:
27: int ch = -1;
28: while ((ch = read()) >= 0) {
29: if (buffer == null) {
30: buffer = new StringBuffer();
31: }
32: if (ch == '\r') {
33: ch = read();
34: if (ch > 0 && ch != '\n') {
35: unread(ch);
36: }
37: break;
38: } else if (ch == '\n') {
39: break;
40: }
41: buffer.append((char) ch);
42: }
43: return buffer;
44: }
45:
46: }
|