I build a Web Server in java, which I get request (as a socket) and process it.
I am required to first print the entire request and then process it on.
Here’s my code snippet:
public HttpRequest(Socket socket) throws Exception
{
this.socket = socket;
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
printRequest(input);
// Do More...
}
The problem is that from this point on, the BufferedReader is in its end and I can’t seem to find a way to get it back to the beginning. The printRequest() method prints the entire request from the BufferedReader with a while loop and readline() actions).
Any ideas how I can fix this?
You can read the content in a
bytearray, and then useByteArrayInputStreamany time you neeed it: