okio.Buffer.clear()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(78)

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

Buffer.clear介绍

[英]Discards all bytes in this buffer. Calling this method when you're done with a buffer will return its segments to the pool.
[中]丢弃此缓冲区中的所有字节。处理完缓冲区后调用此方法会将其段返回到池中。

代码示例

代码示例来源:origin: square/wire

public final Builder<M, B> clearUnknownFields() {
 unknownFieldsByteString = ByteString.EMPTY;
 if (unknownFieldsBuffer != null) {
  unknownFieldsBuffer.clear();
  unknownFieldsBuffer = null;
 }
 unknownFieldsWriter = null;
 return this;
}

代码示例来源:origin: square/okio

@Override public void close() throws IOException {
  if (closed) return;
  closed = true;
  markBuffer.clear();
  super.close();
 }
}

代码示例来源:origin: square/moshi

@Override public void close() throws IOException {
 peeked = PEEKED_NONE;
 scopes[0] = JsonScope.CLOSED;
 stackSize = 1;
 buffer.clear();
 source.close();
}

代码示例来源:origin: apollographql/apollo-android

@Override public void close() throws IOException {
 peeked = PEEKED_NONE;
 stack[0] = JsonScope.CLOSED;
 stackSize = 1;
 buffer.clear();
 source.close();
}

代码示例来源:origin: square/okhttp

@Override public void close() throws IOException {
  long bytesDiscarded;
  synchronized (Http2Stream.this) {
   closed = true;
   bytesDiscarded = readBuffer.size();
   readBuffer.clear();
   Http2Stream.this.notifyAll(); // TODO(jwilson): Unnecessary?
  }
  if (bytesDiscarded > 0) {
   updateConnectionFlowControl(bytesDiscarded);
  }
  cancelStreamIfNecessary();
 }
}

代码示例来源:origin: square/okio

/** Resets {@linkplain #source() the source} to {@code userOffset}. */
public void reset(long userOffset) throws IOException {
 if (closed) {
  throw new IllegalStateException("closed");
 }
 if (userOffset < mark // userOffset is before mark.
   || userOffset > limit // userOffset is beyond limit.
   || userOffset > mark + markBuffer.size() // userOffset is in the future.
   || offset - userBuffer.size() > limit) { // Stream advanced beyond limit.
  throw new IOException("cannot reset to " + userOffset + ": out of range");
 }
 // Clear userBuffer to cause data at 'offset' to be returned by the next read.
 offset = userOffset;
 userBuffer.clear();
}

代码示例来源:origin: square/okhttp

/**
 * Either writes this request to {@code sink} or measures its content length. We have one method
 * do double-duty to make sure the counting and content are consistent, particularly when it comes
 * to awkward operations like measuring the encoded length of header strings, or the
 * length-in-digits of an encoded integer.
 */
private long writeOrCountBytes(@Nullable BufferedSink sink, boolean countBytes) {
 long byteCount = 0L;
 Buffer buffer;
 if (countBytes) {
  buffer = new Buffer();
 } else {
  buffer = sink.buffer();
 }
 for (int i = 0, size = encodedNames.size(); i < size; i++) {
  if (i > 0) buffer.writeByte('&');
  buffer.writeUtf8(encodedNames.get(i));
  buffer.writeByte('=');
  buffer.writeUtf8(encodedValues.get(i));
 }
 if (countBytes) {
  byteCount = buffer.size();
  buffer.clear();
 }
 return byteCount;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

@Override public void close() throws IOException {
  long bytesDiscarded;
  synchronized (Http2Stream.this) {
   closed = true;
   bytesDiscarded = readBuffer.size();
   readBuffer.clear();
   Http2Stream.this.notifyAll(); // TODO(jwilson): Unnecessary?
  }
  if (bytesDiscarded > 0) {
   updateConnectionFlowControl(bytesDiscarded);
  }
  cancelStreamIfNecessary();
 }
}

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

/**
 * Either writes this request to {@code sink} or measures its content length. We have one method
 * do double-duty to make sure the counting and content are consistent, particularly when it comes
 * to awkward operations like measuring the encoded length of header strings, or the
 * length-in-digits of an encoded integer.
 */
private long writeOrCountBytes(@Nullable BufferedSink sink, boolean countBytes) {
 long byteCount = 0L;
 Buffer buffer;
 if (countBytes) {
  buffer = new Buffer();
 } else {
  buffer = sink.buffer();
 }
 for (int i = 0, size = encodedNames.size(); i < size; i++) {
  if (i > 0) buffer.writeByte('&');
  buffer.writeUtf8(encodedNames.get(i));
  buffer.writeByte('=');
  buffer.writeUtf8(encodedValues.get(i));
 }
 if (countBytes) {
  byteCount = buffer.size();
  buffer.clear();
 }
 return byteCount;
}

代码示例来源:origin: square/okio

markBuffer.clear();
mark = -1L;
limit = -1L;

代码示例来源: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/okhttp

} else if (countBytes) {
 byteCountBuffer.clear();
 return -1L;
byteCountBuffer.clear();

代码示例来源:origin: square/okio

@Override public ByteString call() throws Exception {
  Buffer blackhole = new Buffer();
  HashingSink hashingSink = HashingSink.sha1(blackhole);
  Buffer buffer = new Buffer();
  while (pipe.source().read(buffer, Long.MAX_VALUE) != -1) {
   hashingSink.write(buffer, buffer.size());
   blackhole.clear();
  }
  pipe.source().close();
  return hashingSink.hash();
 }
});

代码示例来源:origin: com.squareup.okhttp3/okhttp

} else if (countBytes) {
 byteCountBuffer.clear();
 return -1L;
byteCountBuffer.clear();

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

@Override public void close() throws IOException {
 synchronized (FramedStream.this) {
  closed = true;
  readBuffer.clear();
  FramedStream.this.notifyAll();
 }
 cancelStreamIfNecessary();
}

代码示例来源:origin: duzechao/OKHttpUtils

@Override public void close() throws IOException {
 synchronized (FramedStream.this) {
  closed = true;
  readBuffer.clear();
  FramedStream.this.notifyAll();
 }
 cancelStreamIfNecessary();
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public void close() throws IOException {
 synchronized (Http2Stream.this) {
  closed = true;
  readBuffer.clear();
  Http2Stream.this.notifyAll();
 }
 cancelStreamIfNecessary();
}

代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime

@Override public void close() throws IOException {
 peeked = PEEKED_NONE;
 stack[0] = JsonScope.CLOSED;
 stackSize = 1;
 buffer.clear();
 source.close();
}

代码示例来源:origin: com.squareup.moshi/moshi

@Override public void close() throws IOException {
 peeked = PEEKED_NONE;
 scopes[0] = JsonScope.CLOSED;
 stackSize = 1;
 buffer.clear();
 source.close();
}

相关文章