本文整理了Java中okio.Buffer.indexOf()
方法的一些代码示例,展示了Buffer.indexOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.indexOf()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:indexOf
[英]Returns the index of b in this at or beyond fromIndex, or -1 if this buffer does not contain b in that range.
[中]返回此缓冲区中b在fromIndex处或之外的索引,如果此缓冲区不包含该范围内的b,则返回-1。
代码示例来源:origin: square/okio
@Test public void indexOfWithOffset() {
Buffer buffer = new Buffer();
int halfSegment = SEGMENT_SIZE / 2;
buffer.writeUtf8(repeat('a', halfSegment));
buffer.writeUtf8(repeat('b', halfSegment));
buffer.writeUtf8(repeat('c', halfSegment));
buffer.writeUtf8(repeat('d', halfSegment));
assertEquals(0, buffer.indexOf((byte) 'a', 0));
assertEquals(halfSegment - 1, buffer.indexOf((byte) 'a', halfSegment - 1));
assertEquals(halfSegment, buffer.indexOf((byte) 'b', halfSegment - 1));
assertEquals(halfSegment * 2, buffer.indexOf((byte) 'c', halfSegment - 1));
assertEquals(halfSegment * 3, buffer.indexOf((byte) 'd', halfSegment - 1));
assertEquals(halfSegment * 3, buffer.indexOf((byte) 'd', halfSegment * 2));
assertEquals(halfSegment * 3, buffer.indexOf((byte) 'd', halfSegment * 3));
assertEquals(halfSegment * 4 - 1, buffer.indexOf((byte) 'd', halfSegment * 4 - 1));
}
代码示例来源:origin: huxq17/tractor
@Override public long indexOf(byte b) {
return indexOf(b, 0);
}
代码示例来源:origin: huxq17/tractor
@Override public long indexOf(ByteString bytes) throws IOException {
return indexOf(bytes, 0);
}
代码示例来源:origin: huxq17/tractor
@Override public long indexOf(byte b, long fromIndex) throws IOException {
if (closed) throw new IllegalStateException("closed");
while (fromIndex >= buffer.size) {
if (source.read(buffer, Segment.SIZE) == -1) return -1L;
}
long index;
while ((index = buffer.indexOf(b, fromIndex)) == -1) {
fromIndex = buffer.size;
if (source.read(buffer, Segment.SIZE) == -1) return -1L;
}
return index;
}
代码示例来源:origin: huxq17/tractor
@Override public String readUtf8Line() throws EOFException {
long newline = indexOf((byte) '\n');
if (newline == -1) {
return size != 0 ? readUtf8(size) : null;
}
return readUtf8Line(newline);
}
代码示例来源:origin: huxq17/tractor
@Override public long indexOf(ByteString bytes, long fromIndex) throws IOException {
if (bytes.size() == 0) throw new IllegalArgumentException("bytes is empty");
while (true) {
fromIndex = indexOf(bytes.getByte(0), fromIndex);
if (fromIndex == -1) {
return -1;
}
if (rangeEquals(fromIndex, bytes)) {
return fromIndex;
}
fromIndex++;
}
}
代码示例来源:origin: huxq17/tractor
@Override public String readUtf8LineStrict() throws EOFException {
long newline = indexOf((byte) '\n');
if (newline == -1) {
Buffer data = new Buffer();
copyTo(data, 0, Math.min(32, size));
throw new EOFException("\\n not found: size=" + size()
+ " content=" + data.readByteString().hex() + "...");
}
return readUtf8Line(newline);
}
代码示例来源:origin: xing/xing-android-sdk
long keyEnd = body.indexOf((byte) '=');
if (keyEnd == -1) throw new IllegalStateException("Key with no value: " + body.readUtf8());
body.skip(1); // Equals.
long valueEnd = body.indexOf((byte) '&');
String value = valueEnd == -1 ? body.readUtf8() : body.readUtf8(valueEnd);
if (valueEnd != -1) body.skip(1); // Ampersand.
内容来源于网络,如有侵权,请联系作者删除!