本文整理了Java中okio.Buffer.completeSegmentByteCount()
方法的一些代码示例,展示了Buffer.completeSegmentByteCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.completeSegmentByteCount()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:completeSegmentByteCount
[英]Returns the number of bytes in segments that are not writable. This is the number of bytes that can be flushed immediately to an underlying sink without harming throughput.
[中]返回段中不可写的字节数。这是在不影响吞吐量的情况下可以立即刷新到基础接收器的字节数。
代码示例来源:origin: square/okhttp
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
// Determine if this is a buffered write which we can defer until close() flushes.
boolean deferWrite = isFirstFrame
&& contentLength != -1
&& buffer.size() > contentLength - 8192 /* segment size */;
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0 && !deferWrite) {
writeMessageFrame(formatOpcode, emitCount, isFirstFrame, false /* final */);
isFirstFrame = false;
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
// Determine if this is a buffered write which we can defer until close() flushes.
boolean deferWrite = isFirstFrame
&& contentLength != -1
&& buffer.size() > contentLength - 8192 /* segment size */;
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0 && !deferWrite) {
writeMessageFrame(formatOpcode, emitCount, isFirstFrame, false /* final */);
isFirstFrame = false;
}
}
代码示例来源:origin: square/okio
@Test public void completeSegmentByteCountOnEmptyBuffer() {
Buffer buffer = new Buffer();
assertEquals(0, buffer.completeSegmentByteCount());
}
代码示例来源:origin: square/okio
@Test public void completeSegmentByteCountOnBufferWithFullSegments() {
Buffer buffer = new Buffer();
buffer.writeUtf8(repeat('a', SEGMENT_SIZE * 4));
assertEquals(SEGMENT_SIZE * 4, buffer.completeSegmentByteCount());
}
代码示例来源:origin: square/okio
@Test public void completeSegmentByteCountOnBufferWithIncompleteTailSegment() {
Buffer buffer = new Buffer();
buffer.writeUtf8(repeat('a', SEGMENT_SIZE * 4 - 10));
assertEquals(SEGMENT_SIZE * 3, buffer.completeSegmentByteCount());
}
代码示例来源:origin: com.squareup.okhttp/okhttp-ws
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0) {
synchronized (WebSocketWriter.this) {
writeMessageFrameSynchronized(formatOpcode, emitCount, isFirstFrame, false /* final */);
}
isFirstFrame = false;
}
}
代码示例来源:origin: huxq17/tractor
@Override public BufferedSink emitCompleteSegments() throws IOException {
if (closed) throw new IllegalStateException("closed");
long byteCount = buffer.completeSegmentByteCount();
if (byteCount > 0) sink.write(buffer, byteCount);
return this;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp-ws
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
// Determine if this is a buffered write which we can defer until close() flushes.
boolean deferWrite = isFirstFrame
&& contentLength != -1
&& buffer.size() > contentLength - 8192 /* segment size */;
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0 && !deferWrite) {
synchronized (WebSocketWriter.this) {
writeMessageFrameSynchronized(formatOpcode, emitCount, isFirstFrame, false /* final */);
}
isFirstFrame = false;
}
}
代码示例来源:origin: com.github.ljun20160606/okhttp
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
// Determine if this is a buffered write which we can defer until close() flushes.
boolean deferWrite = isFirstFrame
&& contentLength != -1
&& buffer.size() > contentLength - 8192 /* segment size */;
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0 && !deferWrite) {
writeMessageFrame(formatOpcode, emitCount, isFirstFrame, false /* final */);
isFirstFrame = false;
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override public void write(Buffer source, long byteCount) throws IOException {
if (closed) throw new IOException("closed");
buffer.write(source, byteCount);
// Determine if this is a buffered write which we can defer until close() flushes.
boolean deferWrite = isFirstFrame
&& contentLength != -1
&& buffer.size() > contentLength - 8192 /* segment size */;
long emitCount = buffer.completeSegmentByteCount();
if (emitCount > 0 && !deferWrite) {
writeMessageFrame(formatOpcode, emitCount, isFirstFrame, false /* final */);
isFirstFrame = false;
}
}
代码示例来源:origin: huxq17/tractor
@Override public long readAll(Sink sink) throws IOException {
if (sink == null) throw new IllegalArgumentException("sink == null");
long totalBytesWritten = 0;
while (source.read(buffer, Segment.SIZE) != -1) {
long emitByteCount = buffer.completeSegmentByteCount();
if (emitByteCount > 0) {
totalBytesWritten += emitByteCount;
sink.write(buffer, emitByteCount);
}
}
if (buffer.size() > 0) {
totalBytesWritten += buffer.size();
sink.write(buffer, buffer.size());
}
return totalBytesWritten;
}
内容来源于网络,如有侵权,请联系作者删除!