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


Java UnknownHostException类代码示例

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


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

示例1: SnmpEngineImpl

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine Id, engine boots).
 * <P> WARNING : The SnmpEngineId is computed as follow:
 * <ul>
 * <li> If an lcd file is provided containing the property "localEngineID", this property value is used.</li>.
 * <li> If not, if the passed engineID is not null, this engine ID is used.</li>
 * <li> If not, a time based engineID is computed.</li>
 * </ul>
 * This constructor should be called by an <CODE>SnmpEngineFactory</CODE>. Don't call it directly.
 * @param fact The factory used to instantiate this engine.
 * @param lcd The local configuration datastore.
 * @param engineid The engine ID to use. If null is provided, an SnmpEngineId is computed using the current time.
 * @throws UnknownHostException Exception thrown, if the host name located in the property "localEngineID" is invalid.
 */
public SnmpEngineImpl(SnmpEngineFactory fact,
                      SnmpLcd lcd,
                      SnmpEngineId engineid) throws UnknownHostException {

    init(lcd, fact);
    initEngineID();
    if(this.engineid == null) {
        if(engineid != null)
            this.engineid = engineid;
        else
            this.engineid = SnmpEngineId.createEngineId();
    }
    lcd.storeEngineId(this.engineid);
    if (SNMP_LOGGER.isLoggable(Level.FINER)) {
        SNMP_LOGGER.logp(Level.FINER, SnmpEngineImpl.class.getName(),
                "SnmpEngineImpl(SnmpEngineFactory,SnmpLcd,SnmpEngineId)",
                "LOCAL ENGINE ID: " + this.engineid);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:SnmpEngineImpl.java

示例2: connect

import java.net.UnknownHostException; //导入依赖的package包/类
@Override
public TransportClient connect() {
    Settings settings = Settings.builder()
        .put("cluster.name", "elasticsearch")
        .put("client.transport.sniff", true).build();       
    
    try {
        client = new PreBuiltTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst01.as.it.ubc.ca"), 9300))
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst02.as.it.ubc.ca"), 9300));        
    } catch (UnknownHostException uhe) {
        logger.error(uhe.toString());
    }
    
    return client;
}
 
开发者ID:armenak,项目名称:uDetective,代码行数:17,代码来源:ElasticSearchDataSource.java

示例3: requestWithAccept

import java.net.UnknownHostException; //导入依赖的package包/类
@Test
public void requestWithAccept() throws UnknownHostException, IOException, InterruptedException, Exception {
    CoapServer cnn = CoapServerBuilder.newBuilder().transport(0).build();
    cnn.start();

    CoapPacket request = new CoapPacket(new InetSocketAddress("127.0.0.1", SERVER_PORT));
    request.setMethod(Method.GET);
    request.headers().setUriPath("/test2");
    request.setMessageId(1647);

    short[] acceptList = {MediaTypes.CT_APPLICATION_JSON};
    request.headers().setAccept(acceptList);

    assertEquals(Code.C406_NOT_ACCEPTABLE, cnn.makeRequest(request).get().getCode());
    cnn.stop();
}
 
开发者ID:ARMmbed,项目名称:java-coap,代码行数:17,代码来源:ServerIntegrationTest.java

示例4: getServerAddresses

import java.net.UnknownHostException; //导入依赖的package包/类
private Collection<InetSocketAddress> getServerAddresses(byte size)   {
    if (precomputedLists.containsKey(size)) return precomputedLists.get(size);
    ArrayList<InetSocketAddress> list = new ArrayList<InetSocketAddress>(
            size);
    while (size > 0) {
        try {
            list.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, size}), 1234 + size));
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        --size;
    }
    precomputedLists.put(size, list);
    return list;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:StaticHostProviderTest.java

示例5: getStackTraceString

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Handy function to get a loggable stack trace from a Throwable
 * @param tr An exception to log
 */
public static String getStackTraceString(Throwable tr) {
    if (tr == null) {
        return "";
    }

    // This is to reduce the amount of log spew that apps do in the non-error
    // condition of the network being unavailable.
    Throwable t = tr;
    while (t != null) {
        if (t instanceof UnknownHostException) {
            return "";
        }
        t = t.getCause();
    }

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    tr.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}
 
开发者ID:alibaba,项目名称:virtualview_tools,代码行数:26,代码来源:Log.java

示例6: createOspfInterface1

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Utility for test method.
 */
private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException {
    ospfInterface = new OspfInterfaceImpl();
    OspfAreaImpl ospfArea = new OspfAreaImpl();
    OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
            OspfInterfaceChannelHandler.class);
    ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
                              Ip4Address.valueOf("1.1.1.1"), 2,
                              topologyForDeviceAndLink);
    ospfNbr.setState(OspfNeighborState.FULL);
    ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
    ospfInterface = new OspfInterfaceImpl();
    ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
    ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
    ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
    ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
    ospfInterface.setHelloIntervalTime(20);
    ospfInterface.setInterfaceType(2);
    ospfInterface.setReTransmitInterval(2000);
    ospfInterface.setMtu(6500);
    ospfInterface.setRouterDeadIntervalTime(1000);
    ospfInterface.setRouterPriority(1);
    ospfInterface.setInterfaceType(1);
    ospfInterface.addNeighbouringRouter(ospfNbr);
    return ospfInterface;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:OspfInterfaceImplTest.java

示例7: handleResponseError

import java.net.UnknownHostException; //导入依赖的package包/类
@Override
public void handleResponseError(Context context, Throwable t) {
    //用来提供处理所有错误的监听
    //rxjava必要要使用ErrorHandleSubscriber(默认实现Subscriber的onError方法),此监听才生效
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光是只能打印错误,还可以根据不同的错误作出不同的逻辑处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException) {
        msg = "数据解析错误";
    }
    UiUtils.snackbarText(msg);
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:20,代码来源:ResponseErrorListenerImpl.java

示例8: decode

import java.net.UnknownHostException; //导入依赖的package包/类
@Override
public void decode() {
    try {
        this.magic = this.checkMagic();
        this.serverGuid = this.readLong();
        this.clientAddress = this.readAddress();
        this.maximumTransferUnit = this.readUShort();
        this.encryptionEnabled = this.readBoolean();
    } catch (UnknownHostException e) {
        this.failed = true;
        this.magic = false;
        this.serverGuid = 0;
        this.clientAddress = null;
        this.maximumTransferUnit = 0;
        this.encryptionEnabled = false;
        this.clear();
    }
}
 
开发者ID:KernelFreeze,项目名称:BedrockProxy,代码行数:19,代码来源:OpenConnectionResponseTwo.java

示例9: getLocalHostName

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Retrieve the name of the current host. Multihomed hosts may restrict the
 * hostname lookup to a specific interface and nameserver with {@link
 * org.apache.hadoop.fs.CommonConfigurationKeysPublic#HADOOP_SECURITY_DNS_INTERFACE_KEY}
 * and {@link org.apache.hadoop.fs.CommonConfigurationKeysPublic#HADOOP_SECURITY_DNS_NAMESERVER_KEY}
 *
 * @param conf Configuration object. May be null.
 * @return
 * @throws UnknownHostException
 */
static String getLocalHostName(@Nullable Configuration conf)
    throws UnknownHostException {
  if (conf != null) {
    String dnsInterface = conf.get(HADOOP_SECURITY_DNS_INTERFACE_KEY);
    String nameServer = conf.get(HADOOP_SECURITY_DNS_NAMESERVER_KEY);

    if (dnsInterface != null) {
      return DNS.getDefaultHost(dnsInterface, nameServer, true);
    } else if (nameServer != null) {
      throw new IllegalArgumentException(HADOOP_SECURITY_DNS_NAMESERVER_KEY +
          " requires " + HADOOP_SECURITY_DNS_INTERFACE_KEY + ". Check your" +
          "configuration.");
    }
  }

  // Fallback to querying the default hostname as we did before.
  return InetAddress.getLocalHost().getCanonicalHostName();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:29,代码来源:SecurityUtil.java

示例10: recordEventUsingNodeIDAndAddress

import java.net.UnknownHostException; //导入依赖的package包/类
@Test
public void recordEventUsingNodeIDAndAddress() throws UnknownHostException {
    NodeID id = generateNodeID();
    InetAddress address = generateIPAddressV4();

    PeerScoringManager manager = createPeerScoringManager();

    manager.recordEvent(id, address, EventType.INVALID_BLOCK);

    PeerScoring result = manager.getPeerScoring(id);

    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
    Assert.assertEquals(1, result.getTotalEventCounter());

    result = manager.getPeerScoring(address);

    Assert.assertNotNull(result);
    Assert.assertFalse(result.isEmpty());
    Assert.assertEquals(1, result.getEventCounter(EventType.INVALID_BLOCK));
    Assert.assertEquals(1, result.getTotalEventCounter());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:PeerScoringManagerTest.java

示例11: isBehindNAT

import java.net.UnknownHostException; //导入依赖的package包/类
public static boolean isBehindNAT() {
    String address = determineLocalIp();
    try {
        //       10.x.x.x | 192.168.x.x | 172.16.x.x .. 172.19.x.x
        byte[] d = InetAddress.getByName(address).getAddress();
        if ((d[0] == 10) ||
                (((0x000000FF & d[0]) == 172) &&
                        ((0x000000F0 & d[1]) == 16)) ||
                (((0x000000FF & d[0]) == 192) &&
                        ((0x000000FF & d[1]) == 168))) {
            return true;
        }
    } catch (UnknownHostException e) {
        Log.e("isBehindAT()" + address, e.getMessage() + "");
    }
    return false;
}
 
开发者ID:aksalj,项目名称:africastalking-android,代码行数:18,代码来源:NetworkUtils.java

示例12: SnmpEngineImpl

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Constructor. A Local Configuration Datastore is passed to the engine. It will be used to store and retrieve data (engine ID, engine boots).
 * <P> WARNING : The SnmpEngineId is computed as follow:
 * <ul>
 * <li> If an lcd file is provided containing the property "localEngineID", this property value is used.</li>.
 * <li> If not, a time based engineID is computed.</li>
 * </ul>
 * When no configuration nor java property is set for the engine ID value, a unique time based engine ID will be generated.
 * This constructor should be called by an <CODE>SnmpEngineFactory</CODE>. Don't call it directly.
 * @param fact The factory used to instantiate this engine.
 * @param lcd The local configuration datastore.
 */
public SnmpEngineImpl(SnmpEngineFactory fact,
                      SnmpLcd lcd) throws UnknownHostException {
    init(lcd, fact);
    initEngineID();
    if(engineid == null)
        engineid = SnmpEngineId.createEngineId();

    lcd.storeEngineId(engineid);

    if (SNMP_LOGGER.isLoggable(Level.FINER)) {
        SNMP_LOGGER.logp(Level.FINER, SnmpEngineImpl.class.getName(),
                "SnmpEngineImpl(SnmpEngineFactory,SnmpLcd)",
                "LOCAL ENGINE ID: " + engineid + " / " +
                "LOCAL ENGINE NB BOOTS: " + boot + " / " +
                "LOCAL ENGINE START TIME: " + getEngineTime());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:SnmpEngineImpl.java

示例13: logExecutions

import java.net.UnknownHostException; //导入依赖的package包/类
@Scheduled(fixedRate = 60000)
    public void logExecutions() throws UnknownHostException {
        logger.info("There are "+runtimeService.createExecutionQuery().count()+" process executions in RB instance on host "+ InetAddress.getLocalHost().getHostName());
        logger.info("There are "+runtimeService.createProcessInstanceQuery().processDefinitionKey("launchCampaign").count()+" launchCampaign process instances in RB instance on host "+ InetAddress.getLocalHost().getHostName());
        logger.info("There are "+runtimeService.createProcessInstanceQuery().processDefinitionKey("tweet-prize").count()+" tweet-prize process instances in RB instance on host "+ InetAddress.getLocalHost().getHostName());
        logger.info("There are "+taskService.createTaskQuery().count()+" tasks in RB instance on host "+ InetAddress.getLocalHost().getHostName());
/*        List<ProcessInstance> procInstanceList = runtimeService.createProcessInstanceQuery().orderByProcessInstanceId().asc().includeProcessVariables().list();
        for(ProcessInstance instance:procInstanceList) {
            logger.debug("Inspecting open process instance with id " + instance.getProcessInstanceId() + " for " + instance.getProcessDefinitionKey() + " started at " + instance.getStartTime());
            logger.debug("Instance suspended? " + instance.isSuspended()+" Instance ended? " + instance.isEnded());
            if (instance.getProcessVariables() != null && instance.getProcessVariables().size() > 0) {
                for (String varKey : instance.getProcessVariables().keySet()) {
                    logger.debug(instance.getProcessInstanceId()+" Variable - " + varKey + " - " + instance.getProcessVariables().get(varKey));
                }
            }
        }

        List<Execution> processExecutions = runtimeService.createExecutionQuery().list();
        for(Execution execution:processExecutions){
            logger.debug("Inspecting open process execution with id " + execution.getId() + " for proc inst " + execution.getRootProcessInstanceId());
            logger.debug("ParentId " + execution.getParentId()+" SuperExecutionId "+execution.getSuperExecutionId());
            logger.debug("Execution suspended? " + execution.isSuspended()+" Execution ended? " + execution.isEnded());
        }*/
    }
 
开发者ID:Activiti,项目名称:activiti-cloud-examples,代码行数:25,代码来源:EnglishCampaign.java

示例14: asRetrofitException

import java.net.UnknownHostException; //导入依赖的package包/类
private Throwable asRetrofitException(Throwable throwable) {
    if (throwable instanceof SocketTimeoutException) {
        return new ServerNotAvailableException();
    } else if (throwable instanceof UnknownHostException) {
        return new NoInternetConnectionException();
    } else if (throwable instanceof HttpException) {
        String url;
        HttpException httpException = (HttpException) throwable;
        if (httpException.response() != null) {
            url = httpException.response().raw().request().url().toString();
            ResponseBody body;
            if (httpException.response().isSuccessful())
                body = httpException.response().raw().body();
            else
                body = httpException.response().errorBody();

            try {
                ErrorNodeResponse error = parseNodeError(body);
                return new ApiNodeException(url, httpException.code(), error, httpException.getMessage());
            } catch (Throwable _ignore) {
                _ignore.printStackTrace();
            }
        }
    }
    return throwable;
}
 
开发者ID:Alezhka,项目名称:JWaves,代码行数:27,代码来源:RxNodeErrorHandlingCallAdapterFactory.java

示例15: init

import java.net.UnknownHostException; //导入依赖的package包/类
/**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occurs
 */
public void init() throws ServletException {
	String file = this.getServletContext().getRealPath(this.getInitParameter("log4j"));
	//从web.xml配置读取,名字一定要和web.xml配置一致
	  if(file != null){
	     PropertyConfigurator.configure(file);
	  }
	// Put your code here
	new CrawlerServer(DefaultConfig.serverPort).start();
	try {
		new WebSocket(DefaultConfig.socketPort).start();
	} catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:zrtzrt,项目名称:CrawlerSYS,代码行数:21,代码来源:CrawlerServlet.java


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