code: private long tryWaitForEnoughBytes(final long bytes) throws IOException {
          // we can only wait for a positive number of bytes
          assert bytes > 0 : "Number of bytes are negative or zero : " + bytes;
  
          // if we haven't enough bytes, the loop starts and wait for enough bytes
          while (bytes > availableBytes) {
              try {
                  // first of all, check for a closed stream
                  if (streamClosed) {
                      // is the stream closed, return only the current available bytes
                      return availableBytes;
                  }
                  // wait for a next loop run and block until a modification is signalized
                  signalModification.acquire();
              } catch (InterruptedException ex) {
                  throw new IOException(ex);
              }
          }
          // return the available bytes (maybe higher as the required bytes)
          return availableBytes;
      }
docs: This method blocks until the stream is closed or enough bytes are
  available, which can be read from the buffer.
  
  @param bytes the number of bytes waiting for.
  @throws IOException If the thread is interrupted.
  @return The available bytes.