本文整理了Java中okio.Source.timeout()
方法的一些代码示例,展示了Source.timeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source.timeout()
方法的具体详情如下:
包路径:okio.Source
类名称: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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!