okio.BufferedSource.rangeEquals()方法的使用及代码示例

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

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

BufferedSource.rangeEquals介绍

暂无

代码示例

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

static boolean isWebPFile(BufferedSource source) throws IOException {
 return source.rangeEquals(0, WEBP_FILE_HEADER_RIFF)
   && source.rangeEquals(8, WEBP_FILE_HEADER_WEBP);
}

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

/**
 * Returns true if the first bytes of {@link #source} are {@code key} followed by a colon or
 * a newline.
 */
private boolean isKey(ByteString key) throws IOException {
 if (source.rangeEquals(0, key)) {
  byte nextByte = source.getBuffer().getByte(key.size());
  return nextByte == ':'
    || nextByte == '\r'
    || nextByte == '\n';
 }
 return false;
}

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

@Override public T convert(ResponseBody value) throws IOException {
  BufferedSource source = value.source();
  try {
   // Moshi has no document-level API so the responsibility of BOM skipping falls to whatever
   // is delegating to it. Since it's a UTF-8-only library as well we only honor the UTF-8 BOM.
   if (source.rangeEquals(0, UTF8_BOM)) {
    source.skip(UTF8_BOM.size());
   }
   JsonReader reader = JsonReader.of(source);
   T result = adapter.fromJson(reader);
   if (reader.peek() != JsonReader.Token.END_DOCUMENT) {
    throw new JsonDataException("JSON document was not fully consumed.");
   }
   return result;
  } finally {
   value.close();
  }
 }
}

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

@Test public void rangeEqualsArgumentValidation() throws IOException {
 // Negative source offset.
 assertFalse(source.rangeEquals(-1, ByteString.encodeUtf8("A")));
 // Negative bytes offset.
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A"), -1, 1));
 // Bytes offset longer than bytes length.
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A"), 2, 1));
 // Negative byte count.
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A"), 0, -1));
 // Byte count longer than bytes length.
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A"), 0, 2));
 // Bytes offset plus byte count longer than bytes length.
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A"), 1, 1));
}

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

@Test public void rangeEquals() throws IOException {
 sink.writeUtf8("A man, a plan, a canal. Panama.");
 sink.emit();
 assertTrue(source.rangeEquals(7 , ByteString.encodeUtf8("a plan")));
 assertTrue(source.rangeEquals(0 , ByteString.encodeUtf8("A man")));
 assertTrue(source.rangeEquals(24, ByteString.encodeUtf8("Panama")));
 assertFalse(source.rangeEquals(24, ByteString.encodeUtf8("Panama. Panama. Panama.")));
}

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

@Test public void rangeEqualsWithOffsetAndCount() throws IOException {
 sink.writeUtf8("A man, a plan, a canal. Panama.");
 sink.emit();
 assertTrue(source.rangeEquals(7 , ByteString.encodeUtf8("aaa plannn"), 2, 6));
 assertTrue(source.rangeEquals(0 , ByteString.encodeUtf8("AAA mannn"), 2, 5));
 assertTrue(source.rangeEquals(24, ByteString.encodeUtf8("PPPanamaaa"), 2, 6));
}

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

@Test public void rangeEqualsOnlyReadsUntilMismatch() throws IOException {
 assumeTrue(factory == Factory.ONE_BYTE_AT_A_TIME_BUFFERED_SOURCE); // Other sources read in chunks anyway.
 sink.writeUtf8("A man, a plan, a canal. Panama.");
 sink.emit();
 assertFalse(source.rangeEquals(0, ByteString.encodeUtf8("A man.")));
 assertEquals("A man,", source.getBuffer().readUtf8());
}

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

public static Charset bomAwareCharset(BufferedSource source, Charset charset) throws IOException {
 if (source.rangeEquals(0, UTF_8_BOM)) {
  source.skip(UTF_8_BOM.size());
  return UTF_8;
 }
 if (source.rangeEquals(0, UTF_16_BE_BOM)) {
  source.skip(UTF_16_BE_BOM.size());
  return UTF_16_BE;
 }
 if (source.rangeEquals(0, UTF_16_LE_BOM)) {
  source.skip(UTF_16_LE_BOM.size());
  return UTF_16_LE;
 }
 if (source.rangeEquals(0, UTF_32_BE_BOM)) {
  source.skip(UTF_32_BE_BOM.size());
  return UTF_32_BE;
 }
 if (source.rangeEquals(0, UTF_32_LE_BOM)) {
  source.skip(UTF_32_LE_BOM.size());
  return UTF_32_LE;
 }
 return charset;
}

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

/**
 * Returns true if the first bytes of {@link #source} are {@code key} followed by a colon or
 * a newline.
 */
private boolean isKey(ByteString key) throws IOException {
 if (source.rangeEquals(0, key)) {
  byte nextByte = source.getBuffer().getByte(key.size());
  return nextByte == ':'
    || nextByte == '\r'
    || nextByte == '\n';
 }
 return false;
}

代码示例来源:origin: apache/servicemix-bundles

public static Charset bomAwareCharset(BufferedSource source, Charset charset) throws IOException {
 if (source.rangeEquals(0, UTF_8_BOM)) {
  source.skip(UTF_8_BOM.size());
  return UTF_8;
 }
 if (source.rangeEquals(0, UTF_16_BE_BOM)) {
  source.skip(UTF_16_BE_BOM.size());
  return UTF_16_BE;
 }
 if (source.rangeEquals(0, UTF_16_LE_BOM)) {
  source.skip(UTF_16_LE_BOM.size());
  return UTF_16_LE;
 }
 if (source.rangeEquals(0, UTF_32_BE_BOM)) {
  source.skip(UTF_32_BE_BOM.size());
  return UTF_32_BE;
 }
 if (source.rangeEquals(0, UTF_32_LE_BOM)) {
  source.skip(UTF_32_LE_BOM.size());
  return UTF_32_LE;
 }
 return charset;
}

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

@Override public T convert(ResponseBody value) throws IOException {
  BufferedSource source = value.source();
  try {
   // Moshi has no document-level API so the responsibility of BOM skipping falls to whatever
   // is delegating to it. Since it's a UTF-8-only library as well we only honor the UTF-8 BOM.
   if (source.rangeEquals(0, UTF8_BOM)) {
    source.skip(UTF8_BOM.size());
   }
   JsonReader reader = JsonReader.of(source);
   T result = adapter.fromJson(reader);
   if (reader.peek() != JsonReader.Token.END_DOCUMENT) {
    throw new JsonDataException("JSON document was not fully consumed.");
   }
   return result;
  } finally {
   value.close();
  }
 }
}

代码示例来源:origin: Tickaroo/tikxml

if (isDocumentBeginning && source.rangeEquals(0, UTF8_BOM)) {
 source.skip(3);

相关文章

微信公众号

最新文章

更多