java.io.IOException.getCause()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中java.io.IOException.getCause()方法的一些代码示例,展示了IOException.getCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOException.getCause()方法的具体详情如下:
包路径:java.io.IOException
类名称:IOException
方法名:getCause

IOException.getCause介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

@Override public void onFailure(Call call, IOException e) {
 synchronized (lock) {
  this.callFailure = (e instanceof UnexpectedException) ? e.getCause() : e;
  lock.notifyAll();
 }
}

代码示例来源:origin: square/okhttp

private boolean isRecoverable(IOException e, boolean requestSendStarted) {
 // If there was a protocol problem, don't recover.
 if (e instanceof ProtocolException) {
  return false;
 }
 // If there was an interruption don't recover, but if there was a timeout connecting to a route
 // we should try the next route (if there is one).
 if (e instanceof InterruptedIOException) {
  return e instanceof SocketTimeoutException && !requestSendStarted;
 }
 // Look for known client-side or negotiation errors that are unlikely to be fixed by trying
 // again with a different route.
 if (e instanceof SSLHandshakeException) {
  // If the problem was a CertificateException from the X509TrustManager,
  // do not retry.
  if (e.getCause() instanceof CertificateException) {
   return false;
  }
 }
 if (e instanceof SSLPeerUnverifiedException) {
  // e.g. a certificate pinning error.
  return false;
 }
 // An example of one we might want to retry with a different route is a problem connecting to a
 // proxy and would manifest as a standard IOException. Unless it is one we know we should not
 // retry, we return true and try a new route.
 return true;
}

代码示例来源:origin: square/okhttp

if (e.getCause() instanceof CertificateException) {
 return false;

代码示例来源:origin: prestodb/presto

@Override public void onFailure(Call call, IOException e) {
 synchronized (lock) {
  this.callFailure = (e instanceof UnexpectedException) ? e.getCause() : e;
  lock.notifyAll();
 }
}

代码示例来源:origin: k9mail/k-9

private static boolean isIOExceptionCausedByEPIPE(IOException e) {
  if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
    return e.getMessage().contains("EPIPE");
  }
  Throwable cause = e.getCause();
  return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE;
}

代码示例来源:origin: signalapp/Signal-Server

@Override
 public Response toResponse(IOException e) {
  if (!(e.getCause() instanceof java.util.concurrent.TimeoutException)) {
   logger.warn("IOExceptionMapper", e);
  }
  return Response.status(503).build();
 }
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void run() {
    List<String> cmdWrapper = new ArrayList<>();
    cmdWrapper.add("nohup");
    cmdWrapper.addAll(cmdlist);
    cmdWrapper.add("&");
    try {
      launchProcess(cmdWrapper, environment);
    } catch (IOException e) {
      LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e);
    }
  }
}).start();

代码示例来源:origin: alibaba/jstorm

@Override
  public void run() {
    List<String> cmdWrapper = new ArrayList<String>();
    cmdWrapper.add("nohup");
    cmdWrapper.addAll(cmdlist);
    cmdWrapper.add("&");
    try {
      launchProcess(cmdWrapper, environment);
    } catch (IOException e) {
      LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e);
    }
  }
}).start();

代码示例来源:origin: spotify/helios

@Override
public void shutDown() throws Exception {
 if (upNode != null) {
  try {
   upNode.close();
  } catch (IOException e) {
   final Throwable cause = fromNullable(e.getCause()).or(e);
   log.warn("Exception on closing up node: {}", cause);
  }
 }
}

代码示例来源:origin: spotify/helios

@Override
public void shutDown() throws Exception {
 if (upNode != null) {
  try {
   upNode.close();
  } catch (IOException e) {
   final Throwable cause = fromNullable(e.getCause()).or(e);
   log.warn("Exception on closing up node: {}", cause);
  }
 }
}

代码示例来源:origin: robovm/robovm

private boolean isEINPROGRESS(IOException e) {
  if (isBlocking()) {
    return false;
  }
  if (e instanceof ConnectException) {
    Throwable cause = e.getCause();
    if (cause instanceof ErrnoException) {
      return ((ErrnoException) cause).errno == EINPROGRESS;
    }
  }
  return false;
}

代码示例来源:origin: confluentinc/ksql

private static KsqlRequest deserialize(final String json) {
  try {
   return OBJECT_MAPPER.readValue(json, KsqlRequest.class);
  } catch (IOException e) {
   if (e.getCause() instanceof RuntimeException) {
    throw (RuntimeException) e.getCause();
   }
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: checkstyle/checkstyle

public void foo() {
    try (final InputStream foo = new ByteArrayInputStream(new byte[512])) {
      foo.read();
    }
    catch (final IOException e) {
      e.getCause();
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Reverse operation of {@link #store(ConfidentialKey, byte[])}
 *
 * @return
 *      null the data has not been previously persisted.
 */
@Override
protected byte[] load(ConfidentialKey key) throws IOException {
  try {
    File f = getFileFor(key);
    if (!f.exists())    return null;
    Cipher sym = Secret.getCipher("AES");
    sym.init(Cipher.DECRYPT_MODE, masterKey);
    try (InputStream fis=Files.newInputStream(f.toPath());
       CipherInputStream cis = new CipherInputStream(fis, sym)) {
      byte[] bytes = IOUtils.toByteArray(cis);
      return verifyMagic(bytes);
    }
  } catch (GeneralSecurityException e) {
    throw new IOException("Failed to load the key: "+key.getId(),e);
  } catch (InvalidPathException e) {
    throw new IOException(e);
  } catch (IOException x) {
    if (x.getCause() instanceof BadPaddingException) {
      return null; // broken somehow
    } else {
      throw x;
    }
  }
}

代码示例来源:origin: prestodb/presto

@SuppressWarnings("unchecked")
  protected <T> T _handleDateTimeException(DeserializationContext ctxt,
       Class<?> type, DateTimeException e0, String value) throws IOException
  {
    try {
      return (T) ctxt.handleWeirdKey(type, value,
          "Failed to deserialize %s: (%s) %s",
          type.getName(), e0.getClass().getName(), e0.getMessage());

    } catch (JsonMappingException e) {
      e.initCause(e0);
      throw e;
    } catch (IOException e) {
      if (null == e.getCause()) {
        e.initCause(e0);
      }
      throw JsonMappingException.fromUnexpectedIOE(e);
    }
  }
}

代码示例来源:origin: prestodb/presto

@SuppressWarnings("unchecked")
protected <R> R _handleDateTimeException(DeserializationContext context,
     DateTimeException e0, String value) throws JsonMappingException
{
  try {
    return (R) context.handleWeirdStringValue(handledType(), value,
        "Failed to deserialize %s: (%s) %s",
        handledType().getName(), e0.getClass().getName(), e0.getMessage());
  } catch (JsonMappingException e) {
    e.initCause(e0);
    throw e;
  } catch (IOException e) {
    if (null == e.getCause()) {
      e.initCause(e0);
    }
    throw JsonMappingException.fromUnexpectedIOE(e);
  }
}

代码示例来源:origin: apache/hbase

private void handleEofException(IOException e) {
 if ((e instanceof EOFException || e.getCause() instanceof EOFException) &&
  logQueue.size() > 1 && this.eofAutoRecovery) {
  try {
   if (fs.getFileStatus(logQueue.peek()).getLen() == 0) {
    LOG.warn("Forcing removal of 0 length log in queue: " + logQueue.peek());
    logQueue.remove();
    currentPosition = 0;
   }
  } catch (IOException ioe) {
   LOG.warn("Couldn't get file length information about log " + logQueue.peek());
  }
 }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testPutFieldsWithDefaultWriteObject() throws Exception {
  try {
    marshalUnmarshal(new CustomWriteObjectMethodObject("test"));
  }
  catch (IOException e) {
    assert e.getCause().getCause() instanceof NotActiveException;
  }
}

代码示例来源:origin: apache/kafka

@Test
public void registerFailure() throws Exception {
  ChannelBuilder channelBuilder = new PlaintextChannelBuilder(null) {
    @Override
    public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize,
        MemoryPool memoryPool) throws KafkaException {
      throw new RuntimeException("Test exception");
    }
    @Override
    public void close() {
    }
  };
  Selector selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", channelBuilder, new LogContext());
  SocketChannel socketChannel = SocketChannel.open();
  socketChannel.configureBlocking(false);
  try {
    selector.register("1", socketChannel);
    fail("Register did not fail");
  } catch (IOException e) {
    assertTrue("Unexpected exception: " + e, e.getCause().getMessage().contains("Test exception"));
    assertFalse("Socket not closed", socketChannel.isOpen());
  }
  selector.close();
}

代码示例来源:origin: apache/hbase

@Test
 public void testWrapException() throws Exception {
  final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0);
  assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException);
  assertTrue(
   wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException);
  assertTrue(wrapException(address, new ConnectionClosingException(
    "Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException);
  assertTrue(
   wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException"))
     .getCause() instanceof CallTimeoutException);
 }
}

相关文章