Results 1 to 8 of 8
  1. #1
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

    Default Problem with InputStream

    Hi,
    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

    Java Code:
    parameterType = InputStream.class
    for(int i=0;i<classNames.size();i++){
    	Object objFilter = classObjects.get(i);
            Method met = classNames.get(i).getMethod(
                                                methodNames.get(i),parameterType);
            Object isrReturned = met.invoke(objFilter,is);
    	
            if(isrReturned instanceof InputStream)
    	      parameterType  = InputStream.class;
            else if(isrReturned instanceof OutputStream)
    	      parameterType = OutputStream.class;
    }
    This problem has been taking way too much time so any help will be highly appreciated.
    Thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  3. #3
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

    Default

    Thank you for the reply, but i checked, the InputStream doesn't support mark() and reset().
    So how do i do it alternatively?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I've deleted my previous reply as I don't trust it, sorry.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by hedonist View Post
    Thank you for the reply, but i checked, the InputStream doesn't support mark() and reset().
    So how do i do it alternatively?
    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?

    edit: hold on, through reflection an InputStream is passed to a method; what do these methods do?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

    Default

    Hi,
    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.

    Regards

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by hedonist View Post
    Hi,
    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.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

    Default

    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.

    Thanks

Similar Threads

  1. Creating an InputStream
    By c26354 in forum New To Java
    Replies: 10
    Last Post: 07-12-2011, 04:48 AM
  2. InputStream problem
    By javabarn in forum New To Java
    Replies: 10
    Last Post: 06-29-2010, 04:09 PM
  3. Java InputStream
    By Bill88 in forum New To Java
    Replies: 10
    Last Post: 09-21-2009, 02:40 PM
  4. Converting InputStream to OutputStream
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-11-2008, 10:13 PM
  5. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 07:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •