當前位置: 首頁>>代碼示例>>Java>>正文


Java SocketTimeoutException類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:wanliyang1990,項目名稱:AppServiceRestFul,代碼行數:23,代碼來源:HttpSubscriber.java

示例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;
}
 
開發者ID:iamBedant,項目名稱:InstantAppStarter,代碼行數:22,代碼來源:ApiErrorUtils.java

示例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());
    }
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:22,代碼來源:SocketProxy.java

示例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());
          }
      }
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:SocketProxy.java

示例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();
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:17,代碼來源:SnmpUtil.java

示例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());
	}
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:12,代碼來源:TestUtil.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:URLConnectionTest.java

示例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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:22,代碼來源:SnmpUtil.java

示例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;
    }
}
 
開發者ID:MikeFot,項目名稱:Java--Steam-Loader,代碼行數:21,代碼來源:RetryPolicyInterceptor.java

示例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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:CallTest.java

示例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));
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:18,代碼來源:UnresponsiveServerTests.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:BugzillaExecutor.java

示例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;
}
 
開發者ID:iamBedant,項目名稱:InstantAppStarter,代碼行數:32,代碼來源:ApiErrorUtils.java

示例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;
}
 
開發者ID:iamBedant,項目名稱:InstantAppStarter,代碼行數:22,代碼來源:ApiErrorUtils.java

示例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;
        }
    };
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:20,代碼來源:SessionBackgroundActionTest.java


注:本文中的java.net.SocketTimeoutException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。