private synchronized long limitedRead(long change) throws APIException {

        if (change != -1) {
            bytesRead += change;
            recheckLength();
        }

        return change;

    }
Updates the current number of bytes read based on the return value of a
read-like operation such as read() or skip(). If the maximum stream
length is exceeded as a result of the read, an APIException indicating
this is thrown.

NOTE: To avoid unnecessary read operations, recheckLength() should be
manually called before performing any read operation. This function will
perform the same checks, but can inherently only do so AFTER the read
operation has occurred.

@param change
    The number of bytes that have been read or skipped, or -1 if the
    read-like operation has failed (and no bytes have been read).

@return
    The provided number of bytes read/skipped.

@throws APIException
    If the read-like operation that occurred has caused the stream
    length to exceed its maximum.
guacamole/src/main/java/org/apache/guacamole/rest/LimitedRequestInputStream.java