title: DataInputStream read not blocking
body: <p>First off forgive me if I am mistaken for how blocking works, to my understanding blocking will pause the thread until it is ready, for exsample when reading user input the program will wait until the user hits return.</p>
  
  <p>My problem is that instead of waiting for data to become available it reads bytes with the value 0. Is there a way to block until data becoms available?</p>
  
  <p>The method readBytes is called in a loop.</p>
  
  <pre><code>public byte[] readBytes(){
    try{
  
       //read the head int that will be 4 bytes telling the number of bytes that follow containing data
       byte[] rawLen = new byte[4];
       socketReader.read(rawLen);
       ByteBuffer bb = ByteBuffer.wrap(rawLen);
       int len = bb.getInt();
  
       byte[] data = new byte[len];
       if (len &gt; 0) {
          socketReader.readFully(data);
       }
  
       return data;
  
    } catch (Exception e){
       e.printStackTrace();
       logError("Failed to read data: " + socket.toString());
       return null;
    }
  }
  </code></pre>