public StartWithIPAddressPermission()

in activeio-core/src/main/java/org/apache/activeio/xnet/hba/StartWithIPAddressPermission.java [38:67]


    public StartWithIPAddressPermission(String mask) {
        Matcher matcher = MASK_VALIDATOR.matcher(mask);
        if (false == matcher.matches()) {
            throw new IllegalArgumentException("Mask " + mask + " does not match pattern " + MASK_VALIDATOR.pattern());
        }

        Byte[] tmpBytes = new Byte[4];
        boolean isWildCard = false;
        int size = 0;
        for (int i = 0; i < 3; i++) {
            String group = matcher.group(i + 1);
            if (group.equals("0")) {
                isWildCard = true;
            } else if (isWildCard) {
                throw new IllegalArgumentException("0 at position " + size + " in mask");
            } else {
                int value = Integer.parseInt(group);
                if (value < 0 || 255 < value) {
                    throw new IllegalArgumentException("byte #" + i + " is not valid.");
                }
                tmpBytes[i] = new Byte((byte) value);
                size++;
            }
        }

        bytes = new byte[size];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = tmpBytes[i].byteValue();
        }
    }