I have a Servlet which has request ratio around 10,000 request/hour.
In which, I got one of these two exception frequently at same line which is around daily 5 to 6 times but not every time when this Servlet is called.
java.io.IOException: Stream closed
at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:312)
at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.read1(BufferedReader.java:205)
at java.io.BufferedReader.read(BufferedReader.java:279)
or
java.io.IOException: Underlying input stream returned zero bytes
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:287)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.read1(BufferedReader.java:205)
at java.io.BufferedReader.read(BufferedReader.java:279)
Both exception occurs at the same line.I don't know why? Same type of all requests excecuted and get responded successfully.
Here is my code :
InputStream ist = request.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(ist));
StringBuffer sb = new StringBuffer();
char[] c = new char[1];
while(in.read(c, 0, 1) == 1) // Getting exception at this line
{
sb.append(c[0]);
}
String payload = sb.toString();
Note : Streams are properly closed at the end of the code.
Is it because of high request ratio? Give solution/suggestion if you have any.
simple servlet(not an async)where I try to get post data which is bind with request. After getting validpayload, it will be processed further but I got this exception before that while reading data.