Read from InputStream in multiple formats

前端 未结 3 1354
情话喂你
情话喂你 2021-01-12 18:31

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

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 19:35

    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.)

提交回复
热议问题