Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Re-using Java InputStreams

Options
  • 23-02-2005 9:59pm
    #1
    Registered Users Posts: 6,316 ✭✭✭


    Can InputStreams be re-used by different readers? i.e.

    BufferedReader isFromClient = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    String s = isFromClient.readLine(); //command coming from client

    if(s is this command) {

    ObjectInputStream objectFromServer = new ObjectInputStream(socket.getInputStream());

    }

    As you can see socket.getInputStream() is being called twice and is going into different readers so my object reader is ****ing up cause it reads the "s" as opposed to the object (EOFException - premature EOF file found).....

    I can't find anyway in Java of getting the ObjectReader to start at the right place ( mark and reset don't work the information is stored inside the bufferedreader not the inputstream ) Has anyone here solved this problem without making a connection from the other way....which is about the only solution I can see. Anyone any ideas???


Comments

  • Registered Users Posts: 6,316 ✭✭✭OfflerCrocGod


    Solved it - it was very easy in the end I just replaced the BufferedReader with and ObjectInputStream it means I just transfer Objects around everywhere, nice and easy solution which actually cuts down on the amount of code in my program :D


Advertisement