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

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

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

Buffer.skip介绍

[英]Discards byteCount bytes from the head of this buffer.
[中]丢弃此缓冲区头部的字节计数字节。

代码示例

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

private static void skipName(Buffer in) throws EOFException {
  // 0 - 63 bytes
  int length = in.readByte();

  if (length < 0) {
   // compressed name pointer, first two bits are 1
   // drop second byte of compression offset
   in.skip(1);
  } else {
   while (length > 0) {
    // skip each part of the domain name
    in.skip(length);
    length = in.readByte();
   }
  }
 }
}

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

@Override public void write(Buffer source, long byteCount) throws IOException {
 if (hasErrors) {
  source.skip(byteCount);
  return;
 }
 try {
  super.write(source, byteCount);
 } catch (IOException e) {
  hasErrors = true;
  onException(e);
 }
}

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

/**
 * Advances the position until after the next newline character. If the line
 * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
 * caller.
 */
private void skipToEndOfLine() throws IOException {
 long index = source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN);
 buffer.skip(index != -1 ? index + 1 : buffer.size());
}

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

private void skipQuotedValue(ByteString runTerminator) throws IOException {
 while (true) {
  long index = source.indexOfElement(runTerminator);
  if (index == -1L) throw syntaxError("Unterminated string");
  if (buffer.getByte(index) == '\\') {
   buffer.skip(index + 1);
   readEscapeCharacter();
  } else {
   buffer.skip(index + 1);
   return;
  }
 }
}

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

private void skipUnquotedValue() throws IOException {
 long i = source.indexOfElement(UNQUOTED_STRING_TERMINALS);
 buffer.skip(i != -1L ? i : buffer.size());
}

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

@Override public void write(Buffer source, long byteCount) throws IOException {
 if (!channel.isOpen()) throw new IllegalStateException("closed");
 if (byteCount == 0) return;
 long remaining = byteCount;
 while (remaining > 0) {
  timeout.throwIfReached();
  try (Buffer.UnsafeCursor ignored = source.readUnsafe(cursor)) {
   cursor.seek(0);
   int length = (int) Math.min(cursor.end - cursor.start, remaining);
   int written = channel.write(ByteBuffer.wrap(cursor.data, cursor.start, length));
   remaining -= written;
   source.skip(written);
  }
 }
}

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

@Override public void write(Buffer source, long byteCount) throws IOException {
 if (hasErrors) {
  source.skip(byteCount);
  return;
 }
 try {
  super.write(source, byteCount);
 } catch (IOException e) {
  hasErrors = true;
  onException(e);
 }
}

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

private void completeEvent(String id, String type, Buffer data) throws IOException {
 skipCrAndOrLf();
 if (data.size() != 0L) {
  lastId = id;
  data.skip(1L); // Leading newline.
  callback.onEvent(id, type, data.readUtf8());
 }
}

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

/**
 * Advances the position until after the next newline character. If the line
 * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
 * caller.
 */
private void skipToEndOfLine() throws IOException {
 long index = source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN);
 buffer.skip(index != -1 ? index + 1 : buffer.size());
}

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

private void skipQuotedValue(ByteString runTerminator) throws IOException {
 while (true) {
  long index = source.indexOfElement(runTerminator);
  if (index == -1L) throw syntaxError("Unterminated string");
  if (buffer.getByte(index) == '\\') {
   buffer.skip(index + 1);
   readEscapeCharacter();
  } else {
   buffer.skip(index + 1);
   return;
  }
 }
}

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

private void skipUnquotedValue() throws IOException {
 long i = source.indexOfElement(UNQUOTED_STRING_TERMINALS);
 buffer.skip(i != -1L ? i : buffer.size());
}

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

@Override public void write(Buffer source, long byteCount) throws IOException {
 log.add("write(" + source + ", " + byteCount + ")");
 source.skip(byteCount);
 throwIfScheduled();
}

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

/**
 * Skips through the next closing block comment.
 */
private boolean skipToEndOfBlockComment() throws IOException {
 long index = source.indexOf(CLOSING_BLOCK_COMMENT);
 boolean found = index != -1;
 buffer.skip(found ? index + CLOSING_BLOCK_COMMENT.size() : buffer.size());
 return found;
}

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

result.add(InetAddress.getByAddress(bytes));
} else {
 buf.skip(length);

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

buffer.skip(buffer.size() - bufferMaxSize);

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

@Test public void inflateIntoNonemptySink() throws Exception {
 for (int i = 0; i < SEGMENT_SIZE; i++) {
  Buffer inflated = new Buffer().writeUtf8(repeat('a', i));
  Buffer deflated = decodeBase64(
    "eJxzz09RyEjNKVAoLdZRKE9VL0pVyMxTKMlIVchIzEspVshPU0jNS8/MS00tKtYDAF6CD5s=");
  InflaterSource source = new InflaterSource(deflated, new Inflater());
  while (source.read(inflated, Integer.MAX_VALUE) != -1) {
  }
  inflated.skip(i);
  assertEquals("God help us, we're in the hands of engineers.", inflated.readUtf8());
 }
}

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

@Test public void deflateIntoNonemptySink() throws Exception {
 String original = "They're moving in herds. They do move in herds.";
 // Exercise all possible offsets for the outgoing segment.
 for (int i = 0; i < SEGMENT_SIZE; i++) {
  Buffer data = new Buffer().writeUtf8(original);
  Buffer sink = new Buffer().writeUtf8(repeat('a', i));
  DeflaterSink deflaterSink = new DeflaterSink(sink, new Deflater());
  deflaterSink.write(data, data.size());
  deflaterSink.close();
  sink.skip(i);
  Buffer inflated = inflate(sink);
  assertEquals(original, inflated.readUtf8());
 }
}

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

@Test public void writeToSpanningSegments() throws Exception {
 Buffer buffer = new Buffer();
 buffer.writeUtf8(repeat('a', SEGMENT_SIZE * 2));
 buffer.writeUtf8(repeat('b', SEGMENT_SIZE * 2));
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 buffer.skip(10);
 buffer.writeTo(out, SEGMENT_SIZE * 3);
 assertEquals(repeat('a', SEGMENT_SIZE * 2 - 10) + repeat('b', SEGMENT_SIZE + 10),
   out.toString());
 assertEquals(repeat('b', SEGMENT_SIZE - 10), buffer.readUtf8(buffer.size()));
}

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

@Test public void readFromPrefixOfBuffer() throws Exception {
  source.writeUtf8("z");
  source.write(r32k);
  source.skip(1);
  source.writeUtf8(TestUtil.repeat('z', SEGMENT_SIZE * 2 - 1));
  HashingSink hashingSink = HashingSink.sha256(sink);
  hashingSink.write(source, r32k.size());
  assertEquals(SHA256_r32k, hashingSink.hash());
 }
}

相关文章