code: public static ByteBuffer readToByteBuffer(InputStream inStream, int maxSize) throws IOException {
          Validate.isTrue(maxSize >= 0, "maxSize must be 0 (unlimited) or larger");
          final ConstrainableInputStream input = ConstrainableInputStream.wrap(inStream, bufferSize, maxSize);
          return input.readToByteBuffer(maxSize);
      }
docs: Read the input stream into a byte buffer. To deal with slow input streams, you may interrupt the thread this
  method is executing on. The data read until being interrupted will be available.
  @param inStream the input stream to read from
  @param maxSize the maximum size in bytes to read from the stream. Set to 0 to be unlimited.
  @return the filled byte buffer
  @throws IOException if an exception occurs whilst reading from the input stream.