本文整理汇总了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;
}
示例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();
}
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}