Handle hostnames with upper-case letters
[webmin.git] / itsecur-firewall / LineInputStream.java
1 // LineInputStream
2 // A stream with some useful stdio-like methods. Can be used either for
3 // inheriting those methods into your own input stream, or for adding them
4 // to some input stream.
5 import java.io.InputStream;
6 import java.io.IOException;
7 import java.io.EOFException;
8
9 public class LineInputStream 
10 {
11         InputStream in;
12
13         LineInputStream(InputStream i)
14                 { in = i; }
15         LineInputStream()
16                 { }
17
18         public int read() throws IOException
19                 { return in.read(); }
20         public int read(byte b[]) throws IOException
21                 { return in.read(b); }
22         public int read(byte b[], int o, int l) throws IOException
23                 { return in.read(b, o, l); }
24         public long skip(long n) throws IOException
25                 { return in.skip(n); }
26         public int available() throws IOException
27                 { return in.available(); }
28         public void close() throws IOException
29                 { in.close(); }
30         public synchronized void mark(int readlimit)
31                 { in.mark(readlimit); }
32         public synchronized void reset() throws IOException
33                 { in.reset(); }
34         public boolean markSupported()
35                 { return in.markSupported(); }
36
37         // gets
38         // Read a line and return it (minus the \n)
39         String gets() throws IOException, EOFException
40         {
41         StringBuffer buf = new StringBuffer();
42         int b;
43         while((b = read()) != '\n') {
44                 if (b == -1) throw new EOFException();
45                 buf.append((char)b);
46                 }
47         if (buf.length() != 0 && buf.charAt(buf.length()-1) == '\r')
48                 buf.setLength(buf.length()-1);  // lose \r
49         return buf.toString();
50         }
51
52         // getw
53         // Read a single word, surrounded by whitespace
54         String getw() throws IOException, EOFException
55         {
56         StringBuffer buf = new StringBuffer();
57         // skip spaces
58         int b;
59         do {
60                 if ((b = read()) == -1) throw new EOFException();
61                 } while(Character.isSpace((char)b));
62         // add characters
63         do {
64                 buf.append((char)b);
65                 if ((b = read()) == -1) throw new EOFException();
66                 } while(!Character.isSpace((char)b));
67         return buf.toString();
68         }
69
70         // readdata
71         // Fill the given array completely, even if read() only reads
72         // some max number of bytes at a time.
73         public int readdata(byte b[]) throws IOException, EOFException
74         {
75         int p = 0;
76         while(p < b.length)
77                 p += read(b, p, b.length-p);
78         return b.length;
79         }
80 }
81