title: BufferedInputStream hanging (not reaching end of file)
body: <p>I have Java SSL/TLS server&amp;client sockets. My client simply sends a file to the Server and Server receives it. Here are my codes:</p>
  
  <p>My client method:</p>
  
  <pre><code>static boolean writeData(BufferedOutputStream bos, File data) {
      FileInputStream fis = new FileInputStream(data);
      BufferedInputStream bis = new BufferdInputStream(fis);
  
      byte[] bytes = new byte[512];
      int count = 0;
      while ((count = bis.read(bytes, 0, bytes.length)) &gt; 0) {
          System.out.println("Sending file...");
          bos.write(dataByte, 0, count);
          System.out.println(count);
      }
      bos.flush();
      System.out.println("File Sent");
  }
  </code></pre>
  
  <p>My server method:</p>
  
  <pre><code>static boolean receiveData(BufferedInputStream bis, File data) {
  
      byte[] bytes = new byte[512];
      int count = 0;
      while ((count = bis.read(bytes, 0, bytes.length)) &gt; 0) {
          System.out.println("Receiving file...");
          // Do something..
          System.out.println(count);
      }
      bos.flush();
      System.out.println("File Received");
  }
  </code></pre>
  
  <p>The problem is, the server hangs inside the while loop.. It never reaches the "File Received" message. </p>
  
  <p>Even if the file is small, the bis.read() method never returns -1 at the end of file for some reason. I tested the methods with a file size of 16 bytes, and the output is as follows:</p>
  
  <p>Client terminal:</p>
  
  <pre><code>&gt; Sending file...
  &gt; 16
  &gt; File Sent
  </code></pre>
  
  <p>Server terminal:</p>
  
  <pre><code>&gt; Receiving file...
  &gt; 16
  </code></pre>
  
  <p>As you can see, the server never reaches the "File Received" message and hangs inside the loop even after the end of stream is reached.. Can anyone guess the reason for this?</p>
  
  <p>Thanks</p>