I have an application which needs to look at fields in a multipart request in several different places of the code. The first time I look at the request, it works just fine, but every time after that it doesn't. Here is a simplified example of what is happening:
Not sure that it is relevant, but in case it is, my readLine() method looks like this:
The request is basically passed around so it is the same request object both times. The first one outputs the first line as expected. In the second one however, line is null.
Interestingly enough, I found the following to be true also:
The stream was closed on the first "in" but not on the second, so why would I be getting this????
Help!!
Code:
private ServletInputStream in;
private HttpServletRequest request;
private byte[] buff = new byte[100*1024];
public Class class1 {
public class1(HttpServletRequest req) {
super();
request = req;
in = request.getInputStream();
String line = readLine();
System.out.println("Testing line1: " + line);
}
}
private ServletInputStream in2;
private HttpServletRequest request;
private byte[] buff = new byte[100*1024];
public Class class2 {
public class2(HttpServletRequest req) {
super();
request = req;
in2 = request.getInputStream();
String line = readLine();
System.out.println("Testing line2: " + line);
}
}
Not sure that it is relevant, but in case it is, my readLine() method looks like this:
Code:
private String readLine() throws IOException {
int len = 0;
String line = null;
len = in.readLine(buff,0,buff.length);
if(len < 0) return null;
line = new String(buff,0,len,"ISO-8859-1");
return line;
}
The request is basically passed around so it is the same request object both times. The first one outputs the first line as expected. In the second one however, line is null.
Interestingly enough, I found the following to be true also:
Code:
private ServletInputStream in;
private ServletInputStream in2;
public Class class3 {
public class3(HttpServletRequest request){
super();
in = request.getInputStream();
if(in != null) {
in.close();
}
in = null;
in2 = request.getInputStream();
String line = in2.readLine();
// IOException OCCURS HERE SAYING: Stream closed
}
}
The stream was closed on the first "in" but not on the second, so why would I be getting this????
Help!!