Roshan
Roshan

Reputation: 2059

convert servletinputstream to sequenceinputstream

I'm receiving servlet which contains inputstream.

InputStream input=req.getInputStream();

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

Upvotes: 0

Views: 1424

Answers (4)

Riccardo Cossu
Riccardo Cossu

Reputation: 2739

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.

Upvotes: 0

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299038

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.

Upvotes: 1

kiran.kumar M
kiran.kumar M

Reputation: 811

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.

Upvotes: 1

Piyush Mattoo
Piyush Mattoo

Reputation: 16143

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);

Upvotes: 0

Related Questions