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


Java SocketTimeoutException.printStackTrace方法代码示例

本文整理汇总了Java中java.net.SocketTimeoutException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java SocketTimeoutException.printStackTrace方法的具体用法?Java SocketTimeoutException.printStackTrace怎么用?Java SocketTimeoutException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.SocketTimeoutException的用法示例。


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

示例1: isHealthy

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
boolean isHealthy(boolean doExtensiveChecks) {
    if (!connected) {
        return false;
    }

    Socket socket;
    BufferedSource source;
    synchronized (this) {
        socket = this.socket;
        source = this.source;
    }
    if (socket == null ||
            source == null ||
            socket.isClosed() ||
            socket.isInputShutdown() ||
            socket.isOutputShutdown()) {
        return false;
    }

    if (doExtensiveChecks) {
        try {
            int readTimeout = socket.getSoTimeout();
            try {
                socket.setSoTimeout(1);
                return !source.exhausted();
            } finally {
                socket.setSoTimeout(readTimeout);
            }
        } catch (SocketTimeoutException ignored) {
            ignored.printStackTrace();
            // Read timed out; socket is good.
        } catch (IOException e) {
            return false; // Couldn't read; socket is closed.
        }
    }

    return true;
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:39,代码来源:RealConnection.java

示例2: main

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
public static void main(String[] args) {
	try {
		loadGitTrending("java");
	} catch (SocketTimeoutException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:YihuaWanglv,项目名称:github-trending,代码行数:9,代码来源:HttpJsoupHelper.java

示例3: intercept

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
    try {
        Response response = chain.proceed(chain.request());
        int code = response.code();
        if (code >= 400 && code <= 600) {
            ToastUtils.showShort(Parse.parseHTTPErrorCode(code));
            return createNew(chain, response.body());
        }
        return response;
    } catch (SocketTimeoutException exception) {
        exception.printStackTrace();
    }
    return createNew(chain, null);
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:16,代码来源:NetworkInterceptor.java

示例4: res

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
private String res(HttpRequestBase method) {
	HttpClientContext context = HttpClientContext.create();
	CloseableHttpResponse response = null;
	String content = RESPONSE_CONTENT;
	try {
		response = client.execute(method, context);//执行GET/POST请求
		HttpEntity entity = response.getEntity();//获取响应实体
		if(entity!=null) {
			Charset charset = ContentType.getOrDefault(entity).getCharset();
			content = EntityUtils.toString(entity, charset);
			EntityUtils.consume(entity);
		}
	} catch(ConnectTimeoutException cte) {
		LOG.error("请求连接超时,由于 " + cte.getLocalizedMessage());
		cte.printStackTrace();
	} catch(SocketTimeoutException ste) {
		LOG.error("请求通信超时,由于 " + ste.getLocalizedMessage());
		ste.printStackTrace();
	} catch(ClientProtocolException cpe) {
		LOG.error("协议错误(比如构造HttpGet对象时传入协议不对(将'http'写成'htp')or响应内容不符合),由于 " + cpe.getLocalizedMessage());
		cpe.printStackTrace();
	} catch(IOException ie) {
		LOG.error("实体转换异常或者网络异常, 由于 " + ie.getLocalizedMessage());
		ie.printStackTrace();
	} finally {
		try {
			if(response!=null) {
				response.close();
			}
			
		} catch(IOException e) {
			LOG.error("响应关闭异常, 由于 " + e.getLocalizedMessage());
		}
		
		if(method!=null) {
			method.releaseConnection();
		} 
		
	}
	
	return content;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:43,代码来源:HttpClientUtil.java

示例5: reportCurrentTime

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
@Scheduled(fixedRate = ONE_DAY)
public void reportCurrentTime() {
	LOGGER.info("The time is now {}", DATE_FORMAT.format(new Date()));
	LOGGER.info("now the task begin..............................");

	String[] modules = CONFIG_REGISTER_MODULE.split(",");
	Map<String, List<Repository>> maps = Maps.newHashMap();
	for (String module : modules) {
		List<Repository> repositorys = Lists.newArrayList();
		try {
			repositorys = HttpJsoupHelper.loadOschinaExplore(module);
		} catch (SocketTimeoutException e) {
			e.printStackTrace();
			LOGGER.error("loading repository " + module + "failure: {}", e);
			try {
				repositorys = HttpJsoupHelper.loadOschinaExplore(module);
			} catch (SocketTimeoutException e1) {
				e1.printStackTrace();
				LOGGER.error("loading repository " + module + "failure again! pass continue... : {}", e);
			}
		}
		maps.put(module, repositorys);
	}

	StringBuilder sb = new StringBuilder();
	for (String key : maps.keySet()) {
		LOGGER.info("begin to get content of : " + key);
		sb.append("\n\n\n## ").append(key).append("\n");
		List<Repository> vs = maps.get(key);
		if (null == vs)
			continue;
		for (Repository repository : vs) {
			LOGGER.info(repository.toString());
			sb.append("\n- ").append("[").append(repository.getTitle()).append("](").append(repository.getLink())
					.append(") : ").append(repository.getDescription());
		}
	}

	FileHelper.writeModule(StaticConfig.Repository.OSCHINA, sb.toString());

	GitHelper.proccess();
}
 
开发者ID:YihuaWanglv,项目名称:github-trending,代码行数:43,代码来源:TaskOschinaExplore.java

示例6: reportCurrentTime

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
@Scheduled(fixedRate = ONE_DAY)
public void reportCurrentTime() {
	LOGGER.info("The time is now {}", DATE_FORMAT.format(new Date()));
	LOGGER.info("now the task begin..............................");

	String[] lans = CONFIG_REGISTER_LANGUAGE.split(",");
	Map<String, List<Repository>> maps = Maps.newHashMap();
	for (String lan : lans) {
		List<Repository> repositorys = Lists.newArrayList();
		try {
			repositorys = HttpJsoupHelper.loadGitTrending(lan);
		} catch (SocketTimeoutException e) {
			e.printStackTrace();
			LOGGER.error("loading repository " + lan + "failure!", e);
			try {
				repositorys = HttpJsoupHelper.loadGitTrending(lan);
			} catch (SocketTimeoutException e1) {
				e1.printStackTrace();
				LOGGER.error("loading repository " + lan + "failure again! pass continue...", e);
			}
		}

		maps.put(lan, repositorys);
	}

	StringBuilder sb = new StringBuilder();
	for (String key : maps.keySet()) {
		LOGGER.info("begin to get content of : " + key);
		sb.append("\n\n\n## ").append(key).append("\n");
		List<Repository> vs = maps.get(key);
		if (null == vs)
			continue;
		for (Repository repository : vs) {
			LOGGER.info(repository.toString());
			sb.append("\n- ").append("[").append(repository.getTitle()).append("](").append(repository.getLink())
					.append(") : ").append(repository.getDescription());
		}
	}

	FileHelper.writeModule(StaticConfig.Repository.GITHUB, sb.toString());

	GitHelper.proccess();
}
 
开发者ID:YihuaWanglv,项目名称:github-trending,代码行数:44,代码来源:TaskGithubTrending.java

示例7: processCommand

import java.net.SocketTimeoutException; //导入方法依赖的package包/类
/**
 *	Process a command string 
 */
private String processCommand(String command){
	String[] tokens = command.split(" ");
	Map<String, String> reqMap = new HashMap<>();

	if (tokens[0].equals("reserve")){
		if(tokens.length<2){
			return "NOTE: not enough tokens in reserve string";
		}
		reqMap.put(MessageFields.REQUEST.toString(), Requests.RESERVE.toString());
		reqMap.put(MessageFields.NAME.toString(), tokens[1]);
	}
		
	
	else if (tokens[0].equals("bookSeat")){
		if(tokens.length<3){
			return "NOTE: not enough tokens in bookseat string";
		}
		reqMap.put(MessageFields.REQUEST.toString(), Requests.BOOKSEAT.toString());
		reqMap.put(MessageFields.NAME.toString(), tokens[1]);
		reqMap.put(MessageFields.SEATNUM.toString(), tokens[2]);
	}

	else if (tokens[0].equals("search")){
		if(tokens.length<2){
			return "NOTE: not enough tokens in search string";
		}
		reqMap.put(MessageFields.REQUEST.toString(), Requests.SEARCH.toString());
		reqMap.put(MessageFields.NAME.toString(), tokens[1]);
	}

	else if (tokens[0].equals("delete")){
		if(tokens.length<2){
			return "NOTE: not enough tokens in delete string";
		}
		reqMap.put(MessageFields.REQUEST.toString(), Requests.DELETE.toString());
		reqMap.put(MessageFields.NAME.toString(), tokens[1]);
	}

	else{
		return "ERROR: No such command";
	}
	
	sendRequest(reqMap);
	Map<String, String> response = receiveResponse();
	
	// if connection to server failed, try to reconnect
	if( response==null ){
		try {
			connectTCP();
		} catch (SocketTimeoutException e) {
			e.printStackTrace();
		}
		sendRequest(reqMap);
		response = receiveResponse();
	}
	
	// print message from server
	String responseString = response.get(MessageFields.MESSAGE.toString());
	return responseString;
}
 
开发者ID:ericaddison,项目名称:Dist_HW_2,代码行数:64,代码来源:Client.java


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