Java 8 SocketTimeoutException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SocketTimeoutException class.

This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException()} 
     */ 
    public void test_Constructor() { 
        SocketTimeoutException e = new SocketTimeoutException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException(String)} 
     */ 
    public void test_ConstructorLjava_lang_String() { 
        SocketTimeoutException e = new SocketTimeoutException("fixture");
        assertEquals("fixture", e.getMessage());
        assertNull(e.getCause());
    } 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
        return null; // unpossible, tell the type-system 
    } 
 
    private void throwRoot() throws SocketTimeoutException {
        throw new SocketTimeoutException("Timed-out reading from socket");
    } 
 
    private void throwInnerWrapper() throws IOException {
        try { 
            throwRoot(); 
        } catch (SocketTimeoutException ste) {
            throw new IOException("Fairly general error doing some IO", ste);
        } 
    } 
 
    private void throwOuterWrapper() { 
        try { 
            throwInnerWrapper(); 
        } catch (IOException e) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException()} 
     */ 
    public void test_Constructor() { 
        SocketTimeoutException e = new SocketTimeoutException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException(String)} 
     */ 
    public void test_ConstructorLjava_lang_String() { 
        SocketTimeoutException e = new SocketTimeoutException("fixture");
        assertEquals("fixture", e.getMessage());
        assertNull(e.getCause());
    } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCause, getLocalizedMessage, getMessage
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException()} 
     */ 
    public void test_Constructor() { 
        SocketTimeoutException e = new SocketTimeoutException();
        assertNull(e.getMessage());
        assertNull(e.getLocalizedMessage());
        assertNull(e.getCause());
    } 
 
    /** 
     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException(String)} 
     */ 
    public void test_ConstructorLjava_lang_String() { 
        SocketTimeoutException e = new SocketTimeoutException("fixture");
        assertEquals("fixture", e.getMessage());
        assertNull(e.getCause());
    } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage
        socket.connect(endpoint, timeout);
      } else { 
        SocketIOWithTimeout.connect(ch, endpoint, timeout);
      } 
    } catch (SocketTimeoutException ste) {
      throw new ConnectTimeoutException(ste.getMessage());
    } 
 
    // There is a very rare case allowed by the TCP specification, such that 
    // if we are trying to connect to an endpoint on the local machine, 
    // and we end up choosing an ephemeral port equal to the destination port, 
    // we will actually end up getting connected to ourself (ie any data we 
    // send just comes right back). This is only possible if the target 
    // daemon is down, so we'll treat it like connection refused. 
    if (socket.getLocalPort() == socket.getPort() &&
        socket.getLocalAddress().equals(socket.getInetAddress())) {
      LOG.info("Detected a loopback TCP socket, disconnecting it");
      socket.close();
      throw new ConnectException(
        "Localhost targeted connection resulted in a loopback. " + 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    /** Check the AMQConnection does send exactly 1 initial header, and deal correctly with 
     * the frame handler throwing an exception when we try to read data 
     */ 
    public void testConnectionSendsSingleHeaderAndTimesOut() { 
        IOException exception = new SocketTimeoutException();
        _mockFrameHandler.setExceptionOnReadingFrames(exception);
        assertEquals(0, _mockFrameHandler.countHeadersSent());
        try { 
            ConnectionParams params = factory.params(Executors.newFixedThreadPool(1));
            new AMQConnection(params, _mockFrameHandler).start();
            fail("Connection should have thrown exception");
        } catch(IOException signal) {
           // As expected 
        } 
        assertEquals(1, _mockFrameHandler.countHeadersSent());
        // _connection.close(0, CLOSE_MESSAGE); 
        List<Throwable> exceptionList = exceptionHandler.getHandledExceptions();
        assertEquals(Collections.<Throwable>singletonList(exception), exceptionList);
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:printStackTrace
        } catch (SocketException e) {
            e.printStackTrace();
            mResponseHandler.sendFailureMessage(e, "socket exception");
            return; 
        } catch (SocketTimeoutException e) {
            e.printStackTrace();
            mResponseHandler.sendFailureMessage(e, "socket time out");
            return; 
        } catch (IOException e) {
            e.printStackTrace();
            mResponseHandler.sendFailureMessage(e, "IOException");
            return; 
        } catch(Exception e) {
            e.printStackTrace();
        } 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	/** {@inheritDoc} */ 
        @Override 
	public void handleTimeout(final MobileMsgRequest request) { 
		getCb().handleException(new SocketTimeoutException("timed out processing request " + request)); 
	} 
	 
        @Override 
	public String toString() { 
	    return new ToStringBuilder(this) 
	        .append("callback", cb) 
	        .toString(); 
	} 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessage, printStackTrace
            	ds.setSoTimeout(socket_timeout);
    			ds.receive(dp);
    			lText = new String(lMsg, 0, dp.getLength());
    			address = dp.getAddress();
        	} catch (SocketTimeoutException e) {
        		Log.i(TAG,e.getMessage());
        		e.printStackTrace();
        	} catch (SocketException e) {
        		Log.i(TAG,e.getMessage());
        		e.printStackTrace();
        	} catch (IOException e) {
        		Log.i(TAG,e.getMessage());
        		e.printStackTrace();
        	}  
    	} 
    	else  
    	{ 
    		Log.i(TAG,"Not connected! Gotta initialize the socket first!");
    	} 
    	 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    @Test 
    public void testNotStaleWhenTimeout() throws Exception { 
        final InputStream instream = Mockito.mock(InputStream.class);
        Mockito.when(socket.getInputStream()).thenReturn(instream);
        Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
            .thenThrow(new SocketTimeoutException());
 
        conn.bind(socket);
        conn.ensureOpen();
 
        Assert.assertFalse(conn.isStale());
    } 
 
    @Test 
    public void testStaleWhenIOError() throws Exception { 
        final InputStream instream = Mockito.mock(InputStream.class);
        Mockito.when(socket.getInputStream()).thenReturn(instream);
        Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
            .thenThrow(new SocketException());
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 SocketTimeoutException Questions & Answers:

See Code Examples for Java 8 SocketTimeoutException Methods: