本文整理汇总了Java中java.net.SocketTimeoutException类的典型用法代码示例。如果您正苦于以下问题:Java SocketTimeoutException类的具体用法?Java SocketTimeoutException怎么用?Java SocketTimeoutException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketTimeoutException类属于java.net包,在下文中一共展示了SocketTimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onError
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public void onError(Throwable e) {
if(subscriberOnListener != null && context != null)
{
if (e instanceof SocketTimeoutException) {
subscriberOnListener.onError(-1001, "网络超时,请检查您的网络状态");
} else if (e instanceof ConnectException) {
subscriberOnListener.onError(-1002, "网络链接中断,请检查您的网络状态");
} else if(e instanceof ExceptionApi){
subscriberOnListener.onError(((ExceptionApi)e).getCode(), ((ExceptionApi)e).getMsg());
}
else
{
subscriberOnListener.onError(-1003, "未知错误:" + e.getMessage());
}
}
else
{
if(disposable != null && !disposable.isDisposed())
disposable.dispose();
}
}
示例2: getErrorMessage
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public String getErrorMessage(Throwable t) {
String errorMessage = "OOPs!! Something went wrong";
Timber.d(t);
if (t instanceof HttpException) {
errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
} else if (t instanceof SocketTimeoutException) {
errorMessage = "SocketTimeoutException";
} else if (t instanceof IOException) {
errorMessage = "Network Gone Down";
}
Throwable cause = t.getCause();
if (cause instanceof RaveException) {
errorMessage = cause.getLocalizedMessage();
}
return errorMessage;
}
示例3: run
import java.net.SocketTimeoutException; //导入依赖的package包/类
public void run() {
try {
while (!socket.isClosed()) {
pause.get().await();
try {
Socket source = socket.accept();
pause.get().await();
if (receiveBufferSize > 0) {
source.setReceiveBufferSize(receiveBufferSize);
}
LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
synchronized (connections) {
connections.add(new Bridge(source, target));
}
} catch (SocketTimeoutException expected) {
}
}
} catch (Exception e) {
LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
}
}
示例4: run
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public void run() {
try {
while (!socket.isClosed()) {
pause.get().await();
try {
Socket source = socket.accept();
pause.get().await();
if (receiveBufferSize > 0) {
source.setReceiveBufferSize(receiveBufferSize);
}
LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
synchronized (connections) {
connections.add(new Bridge(source, target));
}
} catch (SocketTimeoutException expected) {
}
}
} catch (Exception e) {
LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
}
}
示例5: getStringByWalk
import java.net.SocketTimeoutException; //导入依赖的package包/类
public static List<String> getStringByWalk(SnmpAccess snmp, final String oid)
throws SocketTimeoutException, SocketException, AbortedException,
IOException, RepeatedOidException, SnmpResponseException {
List<String> result = new ArrayList<String>();
AbstractWalkProcessor<List<String>> walker =
new AbstractWalkProcessor<List<String>>(result) {
private static final long serialVersionUID = 1L;
public void process(VarBind varbind) {
StringSnmpEntry entry = new StringSnmpEntry(oid, varbind);
result.add(entry.getValue());
}
};
snmp.walk(oid, walker);
return walker.getResult();
}
示例6: initSocket
import java.net.SocketTimeoutException; //导入依赖的package包/类
public static void initSocket(final Socket s, final String host, final int port, final JSONObject error)
throws SocketException, IOException {
final SocketAddress endpoint = new InetSocketAddress(host, port);
try {
s.setSoTimeout(1000);
s.connect(endpoint, 1000);
} catch (SocketTimeoutException | ConnectException | UnknownHostException e) {
error.put("class", e.getClass().getSimpleName());
error.put("message", e.getMessage());
}
}
示例7: readTimeouts
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test public void readTimeouts() throws IOException {
// This relies on the fact that MockWebServer doesn't close the
// connection after a response has been sent. This causes the client to
// try to read more bytes than are sent, which results in a timeout.
MockResponse timeout =
new MockResponse().setBody("ABC").clearHeaders().addHeader("Content-Length: 4");
server.enqueue(timeout);
server.enqueue(new MockResponse().setBody("unused")); // to keep the server alive
URLConnection connection = urlFactory.open(server.url("/").url());
connection.setReadTimeout(1000);
InputStream in = connection.getInputStream();
assertEquals('A', in.read());
assertEquals('B', in.read());
assertEquals('C', in.read());
try {
in.read(); // if Content-Length was accurate, this would return -1 immediately
fail();
} catch (SocketTimeoutException expected) {
}
in.close();
}
示例8: getMultipleSnmpEntries
import java.net.SocketTimeoutException; //导入依赖的package包/类
public static List<SnmpEntry> getMultipleSnmpEntries(SnmpAccess snmp,
final List<String> oids) throws SocketTimeoutException, SocketException,
AbortedException, IOException, SnmpResponseException, NoSuchMibException {
String[] oidarray = oids.toArray(new String[oids.size()]);
Map<String, VarBind> gots = snmp.multiGet(oidarray);
List<SnmpEntry> result = new ArrayList<SnmpEntry>();
for (Map.Entry<String, VarBind> got : gots.entrySet()) {
String oid = got.getKey();
VarBind vb = got.getValue();
PDU.Generic pdu = (PDU.Generic) vb.getPdu();
if (pdu.getErrorStatus() > 0) {
throw new IOException("got ErrorStatus=" + pdu.getErrorStatus());
}
if (SnmpV2ResponseException.noSuchInstance == vb.getV2ResponseException()) {
throw new NoSuchMibException(oid);
}
SnmpEntry se = new SnmpEntry(oid, vb);
result.add(se);
}
return result;
}
示例9: intercept
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public Response intercept(final Chain chain) throws IOException {
final Request request = chain.request();
final Response response;
try {
// try the call
response = chain.proceed(request);
//noinspection IfStatementWithNegatedCondition
if (response.code() != HTTP_CODE_202) {
return response;
} else {
response.body().close();
return repeatRequest(chain, request);
}
} catch (final SocketTimeoutException e) {
throw e;
}
}
示例10: expect100ContinueTimesOutWithoutContinue
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test public void expect100ContinueTimesOutWithoutContinue() throws Exception {
server.enqueue(new MockResponse()
.setSocketPolicy(SocketPolicy.NO_RESPONSE));
client = client.newBuilder()
.readTimeout(500, TimeUnit.MILLISECONDS)
.build();
Request request = new Request.Builder()
.url(server.url("/"))
.header("Expect", "100-continue")
.post(RequestBody.create(MediaType.parse("text/plain"), "abc"))
.build();
Call call = client.newCall(request);
try {
call.execute();
fail();
} catch (SocketTimeoutException expected) {
}
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("", recordedRequest.getBody().readUtf8());
}
示例11: requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration() {
final int socketTimeout = REQUEST_TIMEOUT;
// Client configuration is set arbitrarily low so that the request will be aborted if
// the client configuration is incorrectly honored over the request config
httpClient = new AmazonHttpClient(
new ClientConfiguration().withSocketTimeout(socketTimeout).withRequestTimeout(1).withMaxErrorRetry(0));
try {
EmptyHttpRequest request = newGetRequest();
request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(0));
execute(httpClient, request);
fail("Exception expected");
} catch (AmazonClientException e) {
assertThat(e.getCause(), instanceOf(SocketTimeoutException.class));
}
}
示例12: getNotFoundError
import java.net.SocketTimeoutException; //导入依赖的package包/类
private static String getNotFoundError(CoreException ce) {
IStatus status = ce.getStatus();
Throwable t = status.getException();
if(t instanceof UnknownHostException ||
// XXX maybe a different msg ?
t instanceof SocketTimeoutException ||
t instanceof NoRouteToHostException ||
t instanceof ConnectException)
{
Bugzilla.LOG.log(Level.FINER, null, t);
return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND"); // NOI18N
}
String msg = getMessage(ce);
if(msg != null) {
msg = msg.trim().toLowerCase();
if(HTTP_ERROR_NOT_FOUND.equals(msg)) {
Bugzilla.LOG.log(Level.FINER, "returned error message [{0}]", msg); // NOI18N
return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND"); // NOI18N
}
}
return null;
}
示例13: getErrorMessage
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public String getErrorMessage(Throwable t) {
String errorMessage = "OOPs!! Something went wrong";
Timber.d(t);
if (t instanceof HttpException) {
switch (((HttpException) t).code()){
case 500:
errorMessage = "Server Down Customize message";
break;
case 400:
errorMessage= "Bad Request Customize Message";
break;
default:
break;
}
} else if (t instanceof SocketTimeoutException) {
errorMessage = "Slow Network Connection";
} else if (t instanceof IOException) {
errorMessage = "Network Gone Down";
}
Throwable cause = t.getCause();
if (cause instanceof RaveException) {
errorMessage = "OOPs!! Something went wrong";
}
return errorMessage;
}
示例14: getErrorMessage
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public String getErrorMessage(Throwable t) {
String errorMessage = "OOPs!! Something went wrong";
Timber.d(t);
if (t instanceof HttpException) {
errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
} else if (t instanceof SocketTimeoutException) {
errorMessage = "Internet Problem";
} else if (t instanceof IOException) {
errorMessage = "Internet Problem";
}
Throwable cause = t.getCause();
if (cause instanceof RaveException) {
errorMessage = "Server Bug: "+cause.getLocalizedMessage();
}
return errorMessage;
}
示例15: testRetrySocket
import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test
public void testRetrySocket() throws Exception {
final BackgroundException failure = new BackgroundException(new SocketTimeoutException(""));
SessionBackgroundAction<Void> a = new SessionBackgroundAction<Void>(new StatelessSessionPool(
new TestLoginConnectionService(),
new NullSession(new Host(new TestProtocol(), "t")), PathCache.empty(),
new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new AlertCallback() {
@Override
public boolean alert(final Host repeatableBackgroundAction, final BackgroundException f, final StringBuilder transcript) {
assertEquals(failure, f);
return false;
}
}, new DisabledProgressListener(), new DisabledTranscriptListener()) {
@Override
public Void run(final Session<?> session) throws BackgroundException {
throw failure;
}
};
}