本文整理了Java中okio.Buffer.read()
方法的一些代码示例,展示了Buffer.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.read()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:read
[英]Read and exhaust bytes from in to this.
[中]从中读取并耗尽字节到此。
代码示例来源:origin: square/okhttp
@Override public void write(Buffer source, long byteCount) throws IOException {
long toRead = Math.min(remainingByteCount, byteCount);
if (toRead > 0) {
source.read(buffer, toRead);
}
long toSkip = byteCount - toRead;
if (toSkip > 0) {
source.skip(toSkip);
}
remainingByteCount -= toRead;
receivedByteCount += byteCount;
}
代码示例来源:origin: square/okhttp
buf.read(bytes);
result.add(InetAddress.getByAddress(bytes));
} else {
代码示例来源:origin: square/okio
@Test public void moveAllRequestedBytesWithRead() throws Exception {
Buffer sink = new Buffer();
sink.writeUtf8(repeat('a', 10));
Buffer source = new Buffer();
source.writeUtf8(repeat('b', 15));
assertEquals(10, source.read(sink, 10));
assertEquals(20, sink.size());
assertEquals(5, source.size());
assertEquals(repeat('a', 10) + repeat('b', 10), sink.readUtf8(20));
}
代码示例来源:origin: huxq17/tractor
@Override public void readFully(byte[] sink) throws IOException {
try {
require(sink.length);
} catch (EOFException e) {
// The underlying source is exhausted. Copy the bytes we got before rethrowing.
int offset = 0;
while (buffer.size > 0) {
int read = buffer.read(sink, offset, (int) buffer.size);
if (read == -1) throw new AssertionError();
offset += read;
}
throw e;
}
buffer.readFully(sink);
}
代码示例来源:origin: square/okio
@Test public void moveFewerThanRequestedBytesWithRead() throws Exception {
Buffer sink = new Buffer();
sink.writeUtf8(repeat('a', 10));
Buffer source = new Buffer();
source.writeUtf8(repeat('b', 20));
assertEquals(20, source.read(sink, 25));
assertEquals(30, sink.size());
assertEquals(0, source.size());
assertEquals(repeat('a', 10) + repeat('b', 20), sink.readUtf8(30));
}
代码示例来源:origin: line/armeria
@Override
public long read(Buffer sink, long byteCount) throws IOException {
synchronized (buffer) {
if (sourceClosed) {
throw new IllegalStateException("closed");
}
while (buffer.size() == 0) {
if (sinkClosed) {
if (sinkClosedException == null) {
return -1L;
}
throw new IOException(sinkClosedException);
}
timeout.waitUntilNotified(buffer);
}
final long result = buffer.read(sink, byteCount);
buffer.notifyAll();
return result;
}
}
代码示例来源:origin: square/okhttp
readBytesDelivered = readBuffer.read(sink, Math.min(byteCount, readBuffer.size()));
unacknowledgedBytesRead += readBytesDelivered;
代码示例来源:origin: com.squareup.okhttp3/okhttp
readBytesDelivered = readBuffer.read(sink, Math.min(byteCount, readBuffer.size()));
unacknowledgedBytesRead += readBytesDelivered;
代码示例来源:origin: SonarSource/sonarqube
@Test
public void retrieveSystemInfo_get_information_if_process_is_up() {
Buffer response = new Buffer();
response.read(ProtobufSystemInfo.Section.newBuilder().build().toByteArray());
server.enqueue(new MockResponse().setBody(response));
// initialize registration of process
setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE);
Optional<ProtobufSystemInfo.SystemInfo> info = underTest.retrieveSystemInfo();
assertThat(info.get().getSectionsCount()).isEqualTo(0);
}
代码示例来源:origin: huxq17/tractor
@Override public int read(byte[] sink, int offset, int byteCount) {
return Buffer.this.read(sink, offset, byteCount);
}
代码示例来源:origin: huxq17/tractor
@Override public int read(byte[] sink) {
return read(sink, 0, sink.length);
}
代码示例来源:origin: huxq17/tractor
@Override public void readFully(byte[] sink) throws EOFException {
int offset = 0;
while (offset < sink.length) {
int read = read(sink, offset, sink.length - offset);
if (read == -1) throw new EOFException();
offset += read;
}
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
@Override public void write(Buffer source, long byteCount) throws IOException {
long toRead = Math.min(remainingByteCount, byteCount);
if (toRead > 0) {
source.read(buffer, toRead);
}
long toSkip = byteCount - toRead;
if (toSkip > 0) {
source.skip(toSkip);
}
remainingByteCount -= toRead;
receivedByteCount += byteCount;
}
代码示例来源:origin: com.github.ljun20160606/mockwebserver
@Override public void write(Buffer source, long byteCount) throws IOException {
long toRead = Math.min(remainingByteCount, byteCount);
if (toRead > 0) {
source.read(buffer, toRead);
}
long toSkip = byteCount - toRead;
if (toSkip > 0) {
source.skip(toSkip);
}
remainingByteCount -= toRead;
receivedByteCount += byteCount;
}
代码示例来源:origin: huxq17/tractor
@Override public long read(Buffer sink, long byteCount) throws IOException {
if (sink == null) throw new IllegalArgumentException("sink == null");
if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
if (closed) throw new IllegalStateException("closed");
if (buffer.size == 0) {
long read = source.read(buffer, Segment.SIZE);
if (read == -1) return -1;
}
long toRead = Math.min(byteCount, buffer.size);
return buffer.read(sink, toRead);
}
代码示例来源:origin: com.github.ljun20160606/okhttp
/** Write {@code byteCount} bytes from {@code source} to the file at {@code pos}. */
public void write(long pos, Buffer source, long byteCount) throws IOException {
if (byteCount < 0 || byteCount > source.size()) throw new IndexOutOfBoundsException();
while (byteCount > 0L) {
try {
// Write bytes to the byte[], and tell the ByteBuffer wrapper about 'em.
int toWrite = (int) Math.min(BUFFER_SIZE, byteCount);
source.read(byteArray, 0, toWrite);
byteBuffer.limit(toWrite);
// Copy bytes from the ByteBuffer to the file.
do {
int bytesWritten = fileChannel.write(byteBuffer, pos);
pos += bytesWritten;
} while (byteBuffer.hasRemaining());
byteCount -= toWrite;
} finally {
byteBuffer.clear();
}
}
}
代码示例来源:origin: huxq17/tractor
@Override public int read(byte[] sink, int offset, int byteCount) throws IOException {
checkOffsetAndCount(sink.length, offset, byteCount);
if (buffer.size == 0) {
long read = source.read(buffer, Segment.SIZE);
if (read == -1) return -1;
}
int toRead = (int) Math.min(byteCount, buffer.size);
return buffer.read(sink, offset, toRead);
}
代码示例来源:origin: TedaLIEz/ParsingPlayer
@Override
public long read(Buffer sink, long byteCount) throws IOException {
if (closed) throw new IllegalStateException();
return data.read(sink, byteCount);
}
代码示例来源:origin: huxq17/tractor
@Override public int read(byte[] data, int offset, int byteCount) throws IOException {
if (closed) throw new IOException("closed");
checkOffsetAndCount(data.length, offset, byteCount);
if (buffer.size == 0) {
long count = source.read(buffer, Segment.SIZE);
if (count == -1) return -1;
}
return buffer.read(data, offset, byteCount);
}
代码示例来源:origin: huxq17/SwipeCardsView
@Override public long read(Buffer sink, long byteCount)
throws IOException {
if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
long read;
synchronized (FramedStream.this) {
waitUntilReadable();
checkNotClosed();
if (readBuffer.size() == 0) return -1; // This source is exhausted.
// Move bytes from the read buffer into the caller's buffer.
read = readBuffer.read(sink, Math.min(byteCount, readBuffer.size()));
// Flow control: notify the peer that we're ready for more data!
unacknowledgedBytesRead += read;
if (unacknowledgedBytesRead
>= connection.okHttpSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE) / 2) {
connection.writeWindowUpdateLater(id, unacknowledgedBytesRead);
unacknowledgedBytesRead = 0;
}
}
// Update connection.unacknowledgedBytesRead outside the stream lock.
synchronized (connection) { // Multiple application threads may hit this section.
connection.unacknowledgedBytesRead += read;
if (connection.unacknowledgedBytesRead
>= connection.okHttpSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE) / 2) {
connection.writeWindowUpdateLater(0, connection.unacknowledgedBytesRead);
connection.unacknowledgedBytesRead = 0;
}
}
return read;
}
内容来源于网络,如有侵权,请联系作者删除!