public final Builder<M, B> clearUnknownFields() { unknownFieldsByteString = ByteString.EMPTY; if (unknownFieldsBuffer != null) { unknownFieldsBuffer.clear(); unknownFieldsBuffer = null; } unknownFieldsWriter = null; return this; }
@Override public void close() throws IOException { if (closed) return; closed = true; markBuffer.clear(); super.close(); } }
@Override public void close() throws IOException { peeked = PEEKED_NONE; scopes[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }
@Override public void close() throws IOException { peeked = PEEKED_NONE; stack[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }
@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(); } }
/** 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(); }
/** * 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; }
@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(); } }
/** * 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); } } }
/** * 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; }
markBuffer.clear(); mark = -1L; limit = -1L;
/** * 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); } } }
@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(); } });
@Override public void close() throws IOException { synchronized (FramedStream.this) { closed = true; readBuffer.clear(); FramedStream.this.notifyAll(); } cancelStreamIfNecessary(); }
@Override public void close() throws IOException { synchronized (FramedStream.this) { closed = true; readBuffer.clear(); FramedStream.this.notifyAll(); } cancelStreamIfNecessary(); }
@Override public void close() throws IOException { synchronized (Http2Stream.this) { closed = true; readBuffer.clear(); Http2Stream.this.notifyAll(); } cancelStreamIfNecessary(); }
@Override public void close() throws IOException { peeked = PEEKED_NONE; stack[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }
@Override public void close() throws IOException { peeked = PEEKED_NONE; scopes[0] = JsonScope.CLOSED; stackSize = 1; buffer.clear(); source.close(); }