convert servletinputstream to sequenceinputstream
I'm receiving servlet which contains inputstream.
InputStream input=req.getInputStream();
开发者_C百科
When i type cast the inputstream to sequenceinputstream i ended up with ClassCastException org.apache.catalina.connector.CoyoteInputStream cannot be cast to java.io.SequenceInputStream. Please provide solution
I guess you are still dealing with your other problem. You can't convert a ServletInputStream
to a SequenceInputStream
. You can create a new SequenceInputStream
from the ServletInputStream
, but that won't help you, because you are trying to access the individual parts (and the ServletInputStream
just doesn't have that information). Give it up, you are trying to solve the wrong problem.
If you are dealing with uploaded files, try using Commons / FileUpload instead. See the usage page for examples.
Why do you want to use sequenceinputstream ?
Servlet request can contain only an InputStream. You cannot convert or cast. If your objective is to read the input recieved by the sevlet just continue to read the InputStream.
SequenceInputStream combines two or more input streams into one. It can either be created by passing InputStreamEnumerator like below:
Vector files = new Vector();
files.addElement("/run.bat");
files.addElement("/run.sys");
InputStreamEnumerator e = new InputStreamEnumerator(files);
InputStream input = new SequenceInputStream(e);
or providing two InputStream like below:
InputStream input1 = new FileInputStream("c:\\data\\file1.txt");
InputStream input2 = new FileInputStream("c:\\data\\file2.txt");
InputStream combined = new SequenceInputStream(input1, input2);
What do you mean by "In servlet request they are sending the sequenceinputstream"? Do you mean that the client is sending data reading them from a sequenceinputstream? Any way the two streams (the output one from the client and the client one in the servlet) are completely unrelated, I think you just can't do what you mean. Also looking at org.apache.catalina.connector.CoyoteInputStream API's I see no way of getting the "original" input stream.
精彩评论