okio.Timeout.deadlineNanoTime()方法的使用及代码示例

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

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

Timeout.deadlineNanoTime介绍

[英]Returns the System#nanoTime() when the deadline will be reached.
[中]返回到达截止日期时的系统#nanoTime()。

代码示例

代码示例来源: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 synchronized void deadlineAlreadyReached() {
 Timeout timeout = new Timeout();
 timeout.deadlineNanoTime(System.nanoTime());
 double start = now();
 try {
  timeout.waitUntilNotified(this);
  fail();
 } catch (InterruptedIOException expected) {
  assertEquals("timeout", expected.getMessage());
 }
 assertElapsed(0.0, start);
}

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

@Override public long deadlineNanoTime() {
 return delegate.deadlineNanoTime();
}

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

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

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

/** Set a deadline of now plus {@code duration} time. */
public final Timeout deadline(long duration, TimeUnit unit) {
 if (duration <= 0) throw new IllegalArgumentException("duration <= 0: " + duration);
 if (unit == null) throw new IllegalArgumentException("unit == null");
 return deadlineNanoTime(System.nanoTime() + unit.toNanos(duration));
}

代码示例来源: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: 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: 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);
  }
 }
}

代码示例来源: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: 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: 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);
  }
 }
}

相关文章