how to read the same req buffer twice
I have this problem in the code that I am looking at (done by someone who had been long gone).
The code reads the buffer that has the HttpServletRequest data. After the code reads the buffer here, I want to "reset" it so some other code in another component can read the same buffer again. Right now, when the buffer is read the second time by the other component, that code throws an IOException because there is no data returned (???) for the readLine (only my guess, don't have the other component's source code).
Here is the code I am looking at:
req is input defined as "HttpServletRequest req"
int theLen2 = 0;
theLen2 = req.getContentLength();
BufferedReader reqBody = new BufferedReader
tempLine2 = reqBody.readLine();
I put another BufferedReader and readLine in the code again just to see what happens when the buffer is read a second time, the reg.getContentLength() returns the correct length, but the reqBody.readLine returns nothing so tempLine2 is a null string.
I read from the Java book that a "mark" and "reset" can make the file available for a second read again. But I don't know how to mark it at the beginning of the "req".
And I could not find any other way to make the "req" available again.
Any ideas and/or suggestion will be greatly appreciated.
RE: How to read a request buffer multiple times?
Thanks for the reply.
I changed the "getInputStream()" to a "getReader" and I got the request data the first time. But then I got an exception (Reader already defined) when the other component tried to ge the data from the buffer (my guess only, since I don't have the source code).
How do I make the buffer data available again and how do I make sure a second bufferedReader/readLine will succeed?