0

I have a doubt and I'm looking for internet (google,..) and I don't find anything, no solution valid. I want to pass a OutputStream to InputStream.

I have found like pass of a InputStream to OutputStream, but no backwards.

I have seen this page: "output to input", but it hasn't resolved me anything

I have done some implementations but all are wrongs and I don't know like do it

Thanks.

Community
  • 1
  • 1
Celer
  • 95
  • 7
  • Passing an InputStream to an OutputStream is the only direction it makes sense... (Data read from input will be written to output) What behavior are you expecting?! – Adrian Leonhard Feb 19 '15 at 15:56
  • This is already explained in the page you linked... http://stackoverflow.com/a/5778863/1980909 – Adrian Leonhard Feb 19 '15 at 15:58
  • You'll have to explain your use case and why none of the upvoted answers to the above question are good. Otherwise this will probably be marked as a duplicate. – RealSkeptic Feb 19 '15 at 16:00
  • @bot OP needs the reverse operation. – RealSkeptic Feb 19 '15 at 16:01
  • @RealSkeptic I realized that after reading mk's answer. My bad. – Chetan Kinger Feb 19 '15 at 16:03
  • In this case I want to read a xml file (with JAXB), with Marshall I get OutputStrem and after I return this xml file (or if I have to cut this file then I return a zip file with some xml files) and so I have to pass this OutputStrem to InputStream. I want to do this because I don't want to save anything in disk – Celer Feb 19 '15 at 16:07
  • @Celer add a very small sample of the code that you are using to your question. You will find that when you correctly read something, you will be using an InputStream, not an OutputStream as you are thinking. – mk. Feb 19 '15 at 16:12
  • Something like [How do I XML Files directly to Zip archive](http://stackoverflow.com/q/7129421/4125191)? – RealSkeptic Feb 19 '15 at 16:14

1 Answers1

1

An OutputStream is something you write to, not something that spits things out. It has a write method:

outputstream.write(bytes)

An InputStream is something you read from, not something that eats things up. It has a read method:

inputstream.read(bytes);

So you have to connect an inputstream to an outputstream (things coming in to things going out). It is impossible to connect them the other way around.

mk.
  • 11,360
  • 6
  • 40
  • 54
  • +1. Although, you still stand a risk of downvotes because you haven't answered the quesiton. Maybe add one last paragraph? – Chetan Kinger Feb 19 '15 at 16:02