class BinaryAbstractOutputStream extends BinaryAbstractStream implements BinaryOutputStream {

    protected static int capacity(int curCap, int reqCap) {
        int newCap;

        if (reqCap < MIN_CAP)
            newCap = MIN_CAP;
        else if (reqCap > MAX_ARRAY_SIZE)
            throw new IllegalArgumentException("Required capacity exceeds allowed. Required:" + reqCap);
        else {
            newCap = Math.max(curCap, MIN_CAP);

            while (newCap < reqCap) {
                newCap = newCap << 1;

                if (newCap < 0)
                    newCap = MAX_ARRAY_SIZE;
            }
        }

        return newCap;
    }

}