Problems with InputStream
===

Following is a part of the code snippet that I will be using for my project.

    public String fetchFromStream()
    {
        try
        {
            int charVal;
            StringBuffer sb = new StringBuffer();

            while((charVal = inputStream.read()) > 0) {
                sb.append((char)charVal);
            }
            return sb.toString();
        } catch (Exception e)
        {
            m_log.error("readUntil(..) : " + e.getMessage());
            return null;
        } finally {
            System.out.println("<<<<<<<<<<<<<<<<<<<<<< Called >>>>>>>>>>>>>>>>>>>>>>>>>>>");
        }
    }

Initially the while loop start working pretty fine. But after the probable last character is read from the stream I was expecting to get -1 return value. But this is where my problem starts. The code gets hanged, even the finally block is not executed.

I was debugging this code in Eclipse to see what is actually happening during the run-time. I set a pointer (debug) inside the while loop and was constantly monitoring the StringBuffer getting populated with char values one by one. But suddenly while checking the condition inside the while loop, the debugging control is getting lost and this is the point where the code goes to hangup state !! No exception is thrown as well !!

What is happening here ?