code: public static boolean readFullyOrNothing(InputStream in, byte[] buffer) throws IOException {
          int bytesRead = 0;
          do {
              int count = in.read(buffer, bytesRead, buffer.length - bytesRead);
              if (count < 0) {
                  if (bytesRead == 0) {
                      return false;
                  }
                  throw new EOFException();
              }
              bytesRead += count;
          } while (bytesRead < buffer.length);
          return true;
      }
docs: Fills a buffer from an {@link InputStream}. If it doesn't contain any
  more data, returns {@code false}. If it contains some data, but not
  enough to fill the buffer, {@link EOFException} is thrown.
  
  @param in     the {@link InputStream} to read from
  @param buffer the buffer to fill
  @return {@code true} if the buffer was filled completely,
  {@code false} if there was no data in the {@link InputStream}
  @throws EOFException if there was some, but not enough, data in the
  {@link InputStream} to fill the buffer