當前位置: 首頁>>代碼示例>>Java>>正文


Java Ipv4Range類代碼示例

本文整理匯總了Java中net.ripe.commons.ip.Ipv4Range的典型用法代碼示例。如果您正苦於以下問題:Java Ipv4Range類的具體用法?Java Ipv4Range怎麽用?Java Ipv4Range使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ipv4Range類屬於net.ripe.commons.ip包,在下文中一共展示了Ipv4Range類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: transferInIpv4Block

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
@Transactional
public void transferInIpv4Block(final String range) {
    final AuthoritativeResource resources = resourceDataDao.load(source);

    final Iterable<Ipv4Range> overlaps = containsOrOverlaps(resources, range);
    if (isEmpty(overlaps)) {
        authoritativeResourceDao.create(source, formatIpv4Resource(range));
    } else {
        final Ipv4Range ipv4Range = Ipv4Range.parse(range);

        for (Ipv4Range overlap : overlaps) {
            if (overlap.contains(ipv4Range)) {
                // found parent which completely overlaps range, no need to create a new one
                break;
            } else {
                for (Ipv4Range nonOverlap : ipv4Range.exclude(overlap)) {
                    // create new entry for non-overlapping range
                    authoritativeResourceDao.create(source, nonOverlap.toStringInRangeNotation());
                }
            }
        }
    }
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:24,代碼來源:AuthoritativeResourceService.java

示例2: doTransfer

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
@Override
public List<ActionRequest> doTransfer(final Transfer<Ipv4Range> transfer, final Optional<RpslObject> precedingObject, final RpslObject originalObject, final Optional<RpslObject> followingObject) {
    final List<ActionRequest> requests = Lists.newArrayList();

    final Ipv4Range originalRange = Ipv4Range.parse(originalObject.getKey().toString());
    final List<Ipv4Range> whatIsLeft = originalRange.exclude(transfer.getResource());

    final List<RpslAttribute> originalObjectAttributes = originalObject.getAttributes();

    for (Ipv4Range range : whatIsLeft) {
        final RpslObjectBuilder whatIsLeftRpslObjectBuilder = new RpslObjectBuilder(Lists.newArrayList(originalObjectAttributes));

        for (RpslAttribute rpslAttribute : originalObjectAttributes) {
            if (rpslAttribute.getType() == AttributeType.INETNUM) {
                final RpslAttribute newRange = new RpslAttribute(AttributeType.INETNUM, formatInetnum(range));
                whatIsLeftRpslObjectBuilder.replaceAttribute(rpslAttribute, newRange);
            }
        }

        requests.add(new ActionRequest(whatIsLeftRpslObjectBuilder.get(), Action.CREATE));
    }

    return doNextTransferStep(transfer, precedingObject, originalObject, followingObject, requests);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:25,代碼來源:CreatePlaceholderForWhatIsLeftStage.java

示例3: doTransfer

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
@Override
public List<ActionRequest> doTransfer(final Transfer<Ipv4Range> transfer, final Optional<RpslObject> precedingObject, final RpslObject originalObject, final Optional<RpslObject> followingObject) {
    final List<ActionRequest> requests = Lists.newArrayList();

    final Ipv4Range resource = transfer.getResource();

    if (shouldMergeWithObject(precedingObject, resource) && shouldMergeWithObject(followingObject, resource)) {
        requests.addAll(merge(precedingObject.get(), followingObject.get(), resource));
    } else if (shouldMergeWithObject(precedingObject, resource)) {
        requests.addAll(merge(precedingObject.get(), resource));
    } else if (shouldMergeWithObject(followingObject, resource)) {
        requests.addAll(merge(followingObject.get(), resource));
    } else {
        requests.add(createObject(transfer));
    }

    return doNextTransferStep(transfer, precedingObject, originalObject, followingObject, requests);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:19,代碼來源:CreatePlaceholderForInetnumStage.java

示例4: shouldMergeWithObject

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private boolean shouldMergeWithObject(final Optional<RpslObject> rpslObject, final Ipv4Range resource) {
    if (!rpslObject.isPresent()) {
        return false;
    }

    final Ipv4Range rangeObject = Ipv4Range.parse(rpslObject.get().getKey().toString());
    if (!rangeObject.isConsecutive(resource)) {
        return false;
    }

    final Ipv4Range mergedRange = resource.merge(rangeObject);

    final Ipv4 startLowerBoundForPrefix = mergedRange.start().lowerBoundForPrefix(8);
    final Ipv4 endLowerBoundForPrefix = mergedRange.end().lowerBoundForPrefix(8);

    return startLowerBoundForPrefix.equals(endLowerBoundForPrefix);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:18,代碼來源:CreatePlaceholderForInetnumStage.java

示例5: merge

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private List<ActionRequest> merge(final RpslObject precedingObject, final RpslObject followingObject, final Ipv4Range resource) {
    final List<ActionRequest> requests = Lists.newArrayList();

    Preconditions.checkArgument(precedingObject != null);
    Preconditions.checkArgument(followingObject != null);
    Preconditions.checkArgument(resource != null);

    final Ipv4Range precedingRange = Ipv4Range.parse(precedingObject.getKey().toString());
    final Ipv4Range followingRange = Ipv4Range.parse(followingObject.getKey().toString());

    final Ipv4Range mergedRange = precedingRange.merge(resource).merge(followingRange);

    final RpslObject inetnum = RpslObject.parse(String.format(TEMPLATE, mergedRange.toStringInRangeNotation(), source));

    requests.add(new ActionRequest(precedingObject, Action.DELETE));
    requests.add(new ActionRequest(followingObject, Action.DELETE));
    requests.add(new ActionRequest(inetnum, Action.CREATE));

    return requests;
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:21,代碼來源:CreatePlaceholderForInetnumStage.java

示例6: load

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
public AuthoritativeResource load(final String source) {
    final SortedRangeSet<Asn, AsnRange> autNums = new SortedRangeSet<>();
    final SortedRangeSet<Ipv4, Ipv4Range> inetnums = new SortedRangeSet<>();
    final SortedRangeSet<Ipv6, Ipv6Range> inet6nums = new SortedRangeSet<>();

    jdbcTemplate.query("SELECT resource FROM authoritative_resource WHERE source = ?", new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            String resource = rs.getString(1);
            if (resource.startsWith("AS")) {
                autNums.add(resource.contains("-") ? AsnRange.parse(resource) : Asn.parse(resource).asRange());
            } else if (resource.indexOf(':') >= 0) {
                inet6nums.add(Ipv6Range.parse(resource));
            } else {
                inetnums.add(Ipv4Range.parse(resource));
            }
        }

    }, source);
    return new AuthoritativeResource(autNums, inetnums, inet6nums);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:22,代碼來源:ResourceDataDao.java

示例7: loadFromFile

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
public static void loadFromFile(InputStream inputStream){
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while ((line = br.readLine()) != null) {
            set.add(Ipv4Range.parse(line.trim()));
        }
        inputStream.close();
    } catch (IOException e) {
        // Ignore
    }
}
 
開發者ID:AoEiuV020,項目名稱:VpnProxy,代碼行數:13,代碼來源:ChinaIpMaskManager.java

示例8: containsOrOverlaps

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private Iterable<Ipv4Range> containsOrOverlaps(final AuthoritativeResource resources, final String range) {
    final Ipv4Range ipv4Range = Ipv4Range.parse(range);
    return Iterables.filter(extractIpv4Resources(resources), new Predicate<Ipv4Range>() {
        @Override
        public boolean apply(final Ipv4Range input) {
            return input.contains(ipv4Range) || input.overlaps(ipv4Range);
        }
    });
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:10,代碼來源:AuthoritativeResourceService.java

示例9: extractIpv4Resources

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private SortedRangeSet<Ipv4, Ipv4Range> extractIpv4Resources(final AuthoritativeResource resources) {
    final SortedRangeSet<Ipv4, Ipv4Range> results = new SortedRangeSet<>();
    for (String resource : resources.getResources()) {
        if (IPV4_PATTERN.matcher(resource).matches()) {
            results.add(Ipv4Range.parse(resource));
        }
    }

    return results;
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:11,代碼來源:AuthoritativeResourceService.java

示例10: doTransfer

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
@Override
public List<ActionRequest> doTransfer(final Transfer<Ipv4Range> transfer, final Optional<RpslObject> precedingObject, final RpslObject originalObject, final Optional<RpslObject> followingObject) {
    final List<ActionRequest> requests = Lists.newArrayList();

    requests.add(new ActionRequest(originalObject, Action.DELETE));

    return doNextTransferStep(transfer, precedingObject, originalObject, followingObject, requests);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:9,代碼來源:DeleteOriginalInetnumStage.java

示例11: planOutgoingTransfer

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private List<ActionRequest> planOutgoingTransfer(final String inetnum) {
    final List<ActionRequest> requests = Lists.newArrayList();

    final Collection<RpslObject> searchResults = searchInetnumObject(inetnum, QueryFlag.ALL_LESS);
    validateSearchResults(inetnum, searchResults);
    final RpslObject matchingObject = Iterables.getLast(searchResults);

    if (InetnumTransfer.isNonRipeResource(matchingObject)) {
        // no transfer tasks to be performed
        LOGGER.warn("Inetnum {} is already non-RIPE", inetnum);
    } else {
        final Ipv4Range range = Ipv4Range.parse(inetnum);
        if (isExactMatch(range, matchingObject)) {
            throw new BadRequestException(inetnum + " is an exact match and cannot be transferred out");
        }

        final Optional<RpslObject> preceding = getPrecedingRpslObject(range);
        final Optional<RpslObject> following = getFollowingRpslObject(range);

        final Transfer transfer = InetnumTransfer.buildOutgoing(inetnum);
        requests.addAll(transferOutPipeline.doTransfer(transfer, preceding, matchingObject, following));
    }

    logSteps(requests);

    return requests;
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:28,代碼來源:InetnumTransfersLogic.java

示例12: getPrecedingRpslObject

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private Optional<RpslObject> getPrecedingRpslObject(final Ipv4Range range) {
    if (!range.start().hasPrevious()) {
        return Optional.absent();
    }

    final Ipv4 previous = range.start().previous();
    final Collection<RpslObject> parents = searchInetnumObject(previous.toString(), QueryFlag.ONE_LESS);
    return getNeighbour(parents);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:10,代碼來源:InetnumTransfersLogic.java

示例13: getFollowingRpslObject

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private Optional<RpslObject> getFollowingRpslObject(final Ipv4Range range) {
    if (!range.end().hasNext()) {
        return Optional.absent();
    }

    final Ipv4 next = range.end().next();
    final Collection<RpslObject> parents = searchInetnumObject(next.toString(), QueryFlag.ONE_LESS);
    return getNeighbour(parents);
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:10,代碼來源:InetnumTransfersLogic.java

示例14: parseRangeOrSingleAddress

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
private Ipv4Range parseRangeOrSingleAddress(final CIString pkey) {
    // use whois-common library to parse input
    // to keep backwards compatibility
    // so that 10/8 is parsed as 10.0.0.0/8
    final Ipv4Resource ipv4Resource = Ipv4Resource.parse(pkey);
    return Ipv4Range.from(ipv4Resource.begin()).to(ipv4Resource.end());
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:8,代碼來源:AuthoritativeResource.java

示例15: findInetnumOverlaps

import net.ripe.commons.ip.Ipv4Range; //導入依賴的package包/類
public Iterable<String> findInetnumOverlaps(AuthoritativeResource other) {
    return Iterables.transform(this.inetRanges.intersection(other.inetRanges), new Function<Ipv4Range, String>() {
        @Override
        public String apply(final Ipv4Range input) {
            return input.toStringInRangeNotation();
        }
    });
}
 
開發者ID:RIPE-NCC,項目名稱:whois,代碼行數:9,代碼來源:AuthoritativeResource.java


注:本文中的net.ripe.commons.ip.Ipv4Range類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。