okio.Source.timeout()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(148)

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

Source.timeout介绍

[英]Returns the timeout for this source.
[中]返回此源的超时时间。

代码示例

代码示例来源:origin: apollographql/apollo-android

@Override public Timeout timeout() {
 return responseBodySource.timeout();
}

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

@Override public Timeout timeout() {
 return source.timeout();
}

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

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 8192) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 8192) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

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

@Test public void sourceTimeout() throws Exception {
 Pipe pipe = new Pipe(3L);
 pipe.source().timeout().timeout(1000, TimeUnit.MILLISECONDS);
 double start = now();
 Buffer readBuffer = new Buffer();
 try {
  pipe.source().read(readBuffer, 6L);
  fail();
 } catch (InterruptedIOException expected) {
  assertEquals("timeout", expected.getMessage());
 }
 assertElapsed(1000.0, start);
 assertEquals(0, readBuffer.size());
}

代码示例来源:origin: huxq17/tractor

@Override public Timeout timeout() {
 return delegate.timeout();
}

代码示例来源:origin: huxq17/tractor

@Override public Timeout timeout() {
 return source.timeout();
}

代码示例来源:origin: io.apptik.comm/jus-java

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 8192) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: huxq17/SwipeCardsView

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 2048) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: huxq17/tractor

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 2048) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: duzechao/OKHttpUtils

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 2048) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 8192) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Reads until {@code in} is exhausted or the deadline has been reached. This is careful to not
 * extend the deadline if one exists already.
 */
public static boolean skipAll(Source source, int duration, TimeUnit timeUnit) throws IOException {
 long now = System.nanoTime();
 long originalDuration = source.timeout().hasDeadline()
   ? source.timeout().deadlineNanoTime() - now
   : Long.MAX_VALUE;
 source.timeout().deadlineNanoTime(now + Math.min(originalDuration, timeUnit.toNanos(duration)));
 try {
  Buffer skipBuffer = new Buffer();
  while (source.read(skipBuffer, 8192) != -1) {
   skipBuffer.clear();
  }
  return true; // Success! The source has been exhausted.
 } catch (InterruptedIOException e) {
  return false; // We ran out of time before exhausting the source.
 } finally {
  if (originalDuration == Long.MAX_VALUE) {
   source.timeout().clearDeadline();
  } else {
   source.timeout().deadlineNanoTime(now + originalDuration);
  }
 }
}

相关文章

微信公众号

最新文章

更多