本文整理匯總了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;
}