code: private InputStream readPayload(InputStream in, int len) throws IOException {
      byte[] receiveBuffer = new byte[len];
      int totalRead = 0;
      while (totalRead < len) {
        int currentRead = in.read(receiveBuffer, totalRead, len - totalRead);
        if (currentRead < 0) {
          // server may forcefully close the socket/stream and this will cause InputStream to
          // return -1. Throw EOFException (same what DataInputStream does) to signal up
          // that we are in client disconnect mode
          throw new EOFException("stdin EOF before payload read.");
        }
        totalRead += currentRead;
      }
      return new ByteArrayInputStream(receiveBuffer);
    }
docs: Reads a NailGun chunk payload from {@link #in} and returns an InputStream that reads from that
  chunk.
  
  @param in the InputStream to read the chunk payload from.
  @param len the size of the payload chunk read from the chunkHeader.
  @return an InputStream containing the read data.
  @throws IOException if thrown by the underlying InputStream
  @throws EOFException if EOF is reached by underlying stream before the payload has been read,
  or if underlying stream was closed