0

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

Roshan
  • 2,019
  • 8
  • 36
  • 56
  • Question context (not a duplicate): http://stackoverflow.com/questions/5299064/single-inputstream-containing-two-files-i-want-to-split-those-files – Sean Patrick Floyd Mar 15 '11 at 08:44

4 Answers4

1

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.

kiran.kumar M
  • 811
  • 8
  • 25
1

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.

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
0

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);
Piyush Mattoo
  • 15,454
  • 6
  • 47
  • 56
  • yes.i know how to create sequenceinputstream. In servlet request they are sending the sequenceinputstream . So i want to receive stream as sequenceinputstream . so please provide me the solution. Thanks in advance – Roshan Mar 15 '11 at 06:08
0

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.

Riccardo Cossu
  • 2,699
  • 1
  • 28
  • 47