title: ReadLine on TCPDump-Buffer sometimes blocks until kill tcpdump
body: <p>I have a problem using TCPDump from my Android-Application.
  It is supposed to read the output from tcpdump line by line and process it within my Application. <br><b>The Problem is:</b> <br>Sometimes the code works fine, it reads the captured packets immediately. But sometimes, ReadLine blocks until I kill the tcpdump process from the Linux-Console (killall tcpdump). After doing that, my loop is processed for each line (sometimes 10, sometimes 1 or 2) - which means, the readLine should have worked, but didn´t.
  <br>
  I read about similar problems, but did not find any solution for this problem... <br>THANKS!!</p>
  
  <pre><code>public class ListenActivity extends Activity {
  
  static ArrayList&lt;Packet&gt; packetBuffer = new ArrayList&lt;Packet&gt;();
  static Process tcpDumpProcess = null;
  static ListenThread thread = null;
  public static final String TCPDUMP_COMMAND = "tcpdump -A -s0 | grep -i -e 'Cookie'\n";
  
  private InputStream  inputStream = null;
  private OutputStream outputStream = null;
  
  @Override
  protected void onStart() {
      super.onStart();
      try {
          tcpDumpProcess = new ProcessBuilder().command("su").redirectErrorStream(true).start();
          inputStream = tcpDumpProcess.getInputStream();
          outputStream = tcpDumpProcess.getOutputStream();
          outputStream.write(TCPDUMP_COMMAND.getBytes("ASCII"));
      } catch (Exception e) {
          Log.e("FSE", "", e);
      }
      thread = new ListenThread(new BufferedReader(new InputStreamReader(inputStream)));
      thread.start();
  }
  
  private class ListenThread extends Thread {
  
      public ListenThread(BufferedReader reader) {
          this.reader = reader;
      }
  
      private BufferedReader reader = null;
  
      @Override
      public void run() {
  
          reader = new BufferedReader(new InputStreamReader(inputStream));
          while (true) {
              try {                   
                  String received = reader.readLine();
                  Log.d("FS", received);
                  Packet pReceived = Packet.analyze(received);
                  if (pReceived != null) {
                      packetBuffer.add(pReceived);
                  }
              } catch (Exception e) {
                  Log.e("FSE", "", e);
              }
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>