本文整理了Java中okio.BufferedSource.exhausted()
方法的一些代码示例,展示了BufferedSource.exhausted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedSource.exhausted()
方法的具体详情如下:
包路径:okio.BufferedSource
类名称:BufferedSource
方法名:exhausted
[英]Returns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.
[中]如果此源中没有更多字节,则返回true。这将阻塞,直到有字节要读取或源文件肯定已用尽。
代码示例来源:origin: square/okhttp
/** Returns true if this connection is ready to host new streams. */
public boolean isHealthy(boolean doExtensiveChecks) {
if (socket.isClosed() || socket.isInputShutdown() || socket.isOutputShutdown()) {
return false;
}
if (http2Connection != null) {
return !http2Connection.isShutdown();
}
if (doExtensiveChecks) {
try {
int readTimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(1);
if (source.exhausted()) {
return false; // Stream is exhausted; socket is closed.
}
return true;
} finally {
socket.setSoTimeout(readTimeout);
}
} catch (SocketTimeoutException ignored) {
// Read timed out; socket is good.
} catch (IOException e) {
return false; // Couldn't read; socket is closed.
}
}
return true;
}
代码示例来源:origin: square/okhttp
if (!source.exhausted()) {
rebuildJournal();
} else {
代码示例来源:origin: square/okio
@Test public void readExhaustedSource() throws Exception {
Buffer sink = new Buffer();
sink.writeUtf8(repeat('a', 10));
assertEquals(-1, source.read(sink, 10));
assertEquals(10, sink.size());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readZeroBytesFromSource() throws Exception {
Buffer sink = new Buffer();
sink.writeUtf8(repeat('a', 10));
// Either 0 or -1 is reasonable here. For consistency with Android's
// ByteArrayInputStream we return 0.
assertEquals(-1, source.read(sink, 0));
assertEquals(10, sink.size());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readAllExhausted() throws IOException {
MockSink mockSink = new MockSink();
assertEquals(0, source.readAll(mockSink));
assertTrue(source.exhausted());
mockSink.assertLog();
}
代码示例来源:origin: square/okio
@Test public void sinkCloseDoesntWaitForSourceRead() throws Exception {
Pipe pipe = new Pipe(100L);
pipe.sink().write(new Buffer().writeUtf8("abc"), 3);
pipe.sink().close();
BufferedSource bufferedSource = Okio.buffer(pipe.source());
assertEquals("abc", bufferedSource.readUtf8());
assertTrue(bufferedSource.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readAll() throws IOException {
source.getBuffer().writeUtf8("abc");
sink.writeUtf8("def");
sink.emit();
Buffer sink = new Buffer();
assertEquals(6, source.readAll(sink));
assertEquals("abcdef", sink.readUtf8());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readBytes() throws Exception {
sink.write(new byte[] { (byte) 0xab, (byte) 0xcd });
sink.emit();
assertEquals(0xab, source.readByte() & 0xff);
assertEquals(0xcd, source.readByte() & 0xff);
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readShortLe() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x10
});
sink.emit();
assertEquals((short) 0xcdab, source.readShortLe());
assertEquals((short) 0x10ef, source.readShortLe());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readLong() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x10, (byte) 0x87, (byte) 0x65, (byte) 0x43,
(byte) 0x21, (byte) 0x36, (byte) 0x47, (byte) 0x58, (byte) 0x69, (byte) 0x12, (byte) 0x23,
(byte) 0x34, (byte) 0x45
});
sink.emit();
assertEquals(0xabcdef1087654321L, source.readLong());
assertEquals(0x3647586912233445L, source.readLong());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readIntLe() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x10, (byte) 0x87, (byte) 0x65, (byte) 0x43,
(byte) 0x21
});
sink.emit();
assertEquals(0x10efcdab, source.readIntLe());
assertEquals(0x21436587, source.readIntLe());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readLongLe() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x10, (byte) 0x87, (byte) 0x65, (byte) 0x43,
(byte) 0x21, (byte) 0x36, (byte) 0x47, (byte) 0x58, (byte) 0x69, (byte) 0x12, (byte) 0x23,
(byte) 0x34, (byte) 0x45
});
sink.emit();
assertEquals(0x2143658710efcdabL, source.readLongLe());
assertEquals(0x4534231269584736L, source.readLongLe());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readShort() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x01
});
sink.emit();
assertEquals((short) 0xabcd, source.readShort());
assertEquals((short) 0xef01, source.readShort());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readInt() throws Exception {
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x01, (byte) 0x87, (byte) 0x65, (byte) 0x43,
(byte) 0x21
});
sink.emit();
assertEquals(0xabcdef01, source.readInt());
assertEquals(0x87654321, source.readInt());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readIntSplitAcrossMultipleSegments() throws Exception {
sink.writeUtf8(repeat('a', SEGMENT_SIZE - 3));
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x01
});
sink.emit();
source.skip(SEGMENT_SIZE - 3);
assertEquals(0xabcdef01, source.readInt());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void emptyLines() throws IOException {
data.writeUtf8("\n\n\n");
assertEquals("", source.readUtf8LineStrict());
assertEquals("", source.readUtf8LineStrict());
assertEquals("", source.readUtf8LineStrict());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readShortSplitAcrossMultipleSegments() throws Exception {
sink.writeUtf8(repeat('a', SEGMENT_SIZE - 1));
sink.write(new byte[] { (byte) 0xab, (byte) 0xcd });
sink.emit();
source.skip(SEGMENT_SIZE - 1);
assertEquals((short) 0xabcd, source.readShort());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readLongSplitAcrossMultipleSegments() throws Exception {
sink.writeUtf8(repeat('a', SEGMENT_SIZE - 7));
sink.write(new byte[] {
(byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x01, (byte) 0x87, (byte) 0x65, (byte) 0x43,
(byte) 0x21,
});
sink.emit();
source.skip(SEGMENT_SIZE - 7);
assertEquals(0xabcdef0187654321L, source.readLong());
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void skip() throws Exception {
sink.writeUtf8("a");
sink.writeUtf8(repeat('b', SEGMENT_SIZE));
sink.writeUtf8("c");
sink.emit();
source.skip(1);
assertEquals('b', source.readByte() & 0xff);
source.skip(SEGMENT_SIZE - 2);
assertEquals('b', source.readByte() & 0xff);
source.skip(1);
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void select() throws IOException {
Options options = Options.Companion.of(
ByteString.encodeUtf8("ROCK"),
ByteString.encodeUtf8("SCISSORS"),
ByteString.encodeUtf8("PAPER"));
sink.writeUtf8("PAPER,SCISSORS,ROCK");
sink.emit();
assertEquals(2, source.select(options));
assertEquals(',', source.readByte());
assertEquals(1, source.select(options));
assertEquals(',', source.readByte());
assertEquals(0, source.select(options));
assertTrue(source.exhausted());
}
内容来源于网络,如有侵权,请联系作者删除!