Problem with InputStream
I have to pass InputStream as parameter in two methods. The first method returns the same InputStream and i have to pass this returned InputStream into the second method. Inside the first method i can read all the data from the InputStream using InputSteramReader and BufferedReader but inside the second method i cannot read anything from the InputStream. It takes infinite time when i try and read using InputSteramReader and BufferedReader.
Here is a part of the code:
classNames is an ArrayList that contains the class names which have the method to be called.
classObjects in also an ArrayList that contains the objects of the classes from classNames.
parameterType is a Class variable
This problem has been taking way too much time so any help will be highly appreciated.
parameterType = InputStream.class
Object objFilter = classObjects.get(i);
Method met = classNames.get(i).getMethod(
Object isrReturned = met.invoke(objFilter,is);
if(isrReturned instanceof InputStream)
parameterType = InputStream.class;
else if(isrReturned instanceof OutputStream)
parameterType = OutputStream.class;
I'm no expert in this, so please take this with a grain of salt, but perhaps you're reading to the end of the stream in the first method, and then passing a Stream where the stream position is at the end of the Stream. Does the InputStream that you're using support marking? If so have you tried calling mark(int readLimit) at the start of the first method and then calling reset() at the end of the first method to reset the stream's position back to the beginning?
Thank you for the reply, but i checked, the InputStream doesn't support mark() and reset().
So how do i do it alternatively?
I've deleted my previous reply as I don't trust it, sorry.
The part of code you've shown us doesn't do any reading through an InputStream (as far as I can see). Is there any part in your code that wraps the InputStream in an ObjectInputStream?
Originally Posted by hedonist
edit: hold on, through reflection an InputStream is passed to a method; what do these methods do?
I have wrapped the InputStream in BufferedReader but due to the long nature of the codes i skipped it here.
The methods are contained in separate classes. These classes are filter classes that a user can add in the server side based on the requirements. My program has to read these classes and use the methods to perform different tasks in the server side.
A BufferedReader reads more data (chars) than you know, so the InputStream might already be exhausted when you pass it around to another method. Pass the BufferedReader around or don't use any buffering thing.
Originally Posted by hedonist
Yes, i was thinking about the same thing. But the hard part was that i had to implement an interface in which i had to pass the InputStream around. But i guess the interface was not totally correct or was just a logical representation of the basic idea.