I\'m trying to write a class that reads HTTP requests and responses and parses them. Since the headers are ordinary text it seemed easiest to read them using a Buffe
There is already a class in Java for handling HTTP requests and responses. You should use that instead of trying to parse the response on your own. Parsing HTTP response is more difficult than you think as there are different encoding methods that you have to deal with. It isn't really raw binary data in the response payload. The HttpURLConnection class will parse headers for you and give you InputStream for the payload.
http://download.oracle.com/javase/1.4.2/docs/api/java/net/HttpURLConnection.html
commons-httpclient might save you a heap of work here.
If you don't want to use a ready HTTP client/server implementation like Konstantin proposed, DataInputStream has a readLine
method. It is deprecated since it isn't doing a proper conversion (mostly a direct byte -> char casting conversion), but I think for pure ASCII header lines you should be good.
(You should put a BufferedInputStream under you DataInputStream, since readLine reads each byte individually.)