当前位置: 首页>>代码示例>>Java>>正文


Java AddressNotFoundException类代码示例

本文整理汇总了Java中com.maxmind.geoip2.exception.AddressNotFoundException的典型用法代码示例。如果您正苦于以下问题:Java AddressNotFoundException类的具体用法?Java AddressNotFoundException怎么用?Java AddressNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AddressNotFoundException类属于com.maxmind.geoip2.exception包,在下文中一共展示了AddressNotFoundException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUnkownIpRequired

import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
@Test(expected = AddressNotFoundException.class)
public void testUnkownIpRequired() throws Throwable {
  GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);

  DummpyEvent devent = new DummpyEvent();
  devent.setField("ip_address", "10.0.0.1");

  InternalEvent ievent = new InternalEvent("", null, 0);
  ievent.setEventObj(devent);

  try {
    op.perform(ievent);
  } catch (OperationException e) {
    throw e.getCause();
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:17,代码来源:GeoIpOperationTest.java

示例2: get

import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
/**
 * @param ipAddress IPv4 or IPv6 address to lookup.
 * @return A <T> object with the data for the IP address
 * @throws IOException              if there is an error opening or reading from the file.
 * @throws AddressNotFoundException if the IP address is not in our database
 */
private <T> T get(InetAddress ipAddress, Class<T> cls,
                  String type) throws IOException, AddressNotFoundException {

    String databaseType = this.getMetadata().getDatabaseType();
    if (!databaseType.contains(type)) {
        String caller = Thread.currentThread().getStackTrace()[2]
                .getMethodName();
        throw new UnsupportedOperationException(
                "Invalid attempt to open a " + databaseType
                        + " database using the " + caller + " method");
    }

    ObjectNode node = jsonNodeToObjectNode(reader.get(ipAddress));

    // We throw the same exception as the web service when an IP is not in
    // the database
    if (node == null) {
        throw new AddressNotFoundException("The address "
                + ipAddress.getHostAddress() + " is not in the database.");
    }

    InjectableValues inject = new JsonInjector(locales, ipAddress.getHostAddress());

    return this.om.reader(inject).treeToValue(node, cls);
}
 
开发者ID:maxmind,项目名称:GeoIP2-java,代码行数:32,代码来源:DatabaseReader.java

示例3: getCountry

import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
public Optional<Country> getCountry(InetAddress address) {
    if (geoReader == null) {
        return Optional.empty();
    }

    try {
        return Optional.of(geoReader.country(address).getCountry());
    } catch (AddressNotFoundException notFoundEx) {
        //ignore
    } catch (IOException | GeoIp2Exception ex) {
        logger.error("Failed to lookup country of {}", address, ex);
    }

    return Optional.empty();
}
 
开发者ID:games647,项目名称:Minefana,代码行数:16,代码来源:AnalyticsCore.java

示例4: unknownAddress

import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
private void unknownAddress(DatabaseReader reader) throws IOException,
        GeoIp2Exception {
    this.exception.expect(AddressNotFoundException.class);
    this.exception
            .expectMessage(containsString("The address 10.10.10.10 is not in the database."));
    try {
        reader.city(InetAddress.getByName("10.10.10.10"));
    } finally {
        reader.close();
    }
}
 
开发者ID:maxmind,项目名称:GeoIP2-java,代码行数:12,代码来源:DatabaseReaderTest.java


注:本文中的com.maxmind.geoip2.exception.AddressNotFoundException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。