Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with InputStream
    primarykey
    data
    text
    <p>Following is a part of the code snippet that I will be using for my project.</p> <pre><code>public String fetchFromStream() { try { int charVal; StringBuffer sb = new StringBuffer(); while((charVal = inputStream.read()) &gt; 0) { sb.append((char)charVal); } return sb.toString(); } catch (Exception e) { m_log.error("readUntil(..) : " + e.getMessage()); return null; } finally { System.out.println("&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Called &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"); } } </code></pre> <p>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.</p> <p>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 !!</p> <p>What is happening here ?</p> <p>Edit::</p> <p>This is how I'm getting my InputStream. Basically I'm using Apache Commons Net for Telnet.</p> <pre><code>private TelnetClient getTelnetSession(String hostname, int port) { TelnetClient tc = new TelnetClient(); try { tc.connect(hostname, port != 0 ? port : 23); //These are instance variables inputStream = tc.getInputStream(); outputStream = new PrintStream(tc.getOutputStream()); //More codes... return tc; } catch (SocketException se) { m_log.error("getTelnetSession(..) : " + se.getMessage()); return null; } catch (IOException ioe) { m_log.error("getTelnetSession(..) : " + ioe.getMessage()); return null; } catch (Exception e) { m_log.error("getTelnetSession(..) : " + e.getMessage()); return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload