本文整理了Java中okio.Buffer.getByte()
方法的一些代码示例,展示了Buffer.getByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getByte()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:getByte
[英]Returns the byte at pos.
[中]返回位置处的字节。
代码示例来源:origin: square/okhttp
private static int skipAll(Buffer buffer, byte b) {
int count = 0;
while (!buffer.exhausted() && buffer.getByte(0) == b) {
count++;
buffer.readByte();
}
return count;
}
代码示例来源: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/okhttp
/**
* Consumes the field name of the specified length and the optional colon and its optional
* trailing space. Returns the number of bytes skipped.
*/
private long skipNameAndDivider(long length) throws IOException {
source.skip(length);
if (source.getBuffer().getByte(0) == ':') {
source.skip(1L);
length++;
if (source.getBuffer().getByte(0) == ' ') {
source.skip(1);
length++;
}
}
return length;
}
}
代码示例来源:origin: square/okhttp
/** Returns true if any commas were skipped. */
private static boolean skipWhitespaceAndCommas(Buffer buffer) {
boolean commaFound = false;
while (!buffer.exhausted()) {
byte b = buffer.getByte(0);
if (b == ',') {
buffer.readByte(); // Consume ','.
commaFound = true;
} else if (b == ' ' || b == '\t') {
buffer.readByte(); // Consume space or tab.
} else {
break;
}
}
return commaFound;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
private static int skipAll(Buffer buffer, byte b) {
int count = 0;
while (!buffer.exhausted() && buffer.getByte(0) == b) {
count++;
buffer.readByte();
}
return count;
}
代码示例来源:origin: apollographql/apollo-android
/**
* @param toFind a string to search for. Must not contain a newline.
*/
private boolean skipTo(String toFind) throws IOException {
outer:
for (; source.request(toFind.length());) {
for (int c = 0; c < toFind.length(); c++) {
if (buffer.getByte(c) != toFind.charAt(c)) {
buffer.readByte();
continue outer;
}
}
return true;
}
return false;
}
代码示例来源:origin: square/okhttp
/** Consumes {@code \r}, {@code \r\n}, or {@code \n} from {@link #source}. */
private void skipCrAndOrLf() throws IOException {
if ((source.readByte() & 0xff) == '\r'
&& source.request(1)
&& source.getBuffer().getByte(0) == '\n') {
source.skip(1);
}
}
代码示例来源:origin: square/moshi
private int peekKeyword() throws IOException {
byte c = buffer.getByte(0);
String keyword;
String keywordUpper;
return PEEKED_NONE;
c = buffer.getByte(i);
if (c != keyword.charAt(i) && c != keywordUpper.charAt(i)) {
return PEEKED_NONE;
if (source.request(length + 1) && isLiteral(buffer.getByte(length))) {
return PEEKED_NONE; // Don't match trues, falsey or nullsoft!
代码示例来源:origin: square/okio
@Test public void getByteOfEmptyBuffer() {
Buffer buffer = new Buffer();
try {
buffer.getByte(0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/** Returns true if any commas were skipped. */
private static boolean skipWhitespaceAndCommas(Buffer buffer) {
boolean commaFound = false;
while (!buffer.exhausted()) {
byte b = buffer.getByte(0);
if (b == ',') {
buffer.readByte(); // Consume ','.
commaFound = true;
} else if (b == ' ' || b == '\t') {
buffer.readByte(); // Consume space or tab.
} else {
break;
}
}
return commaFound;
}
代码示例来源:origin: square/okhttp
/**
* Reads a double-quoted string, unescaping quoted pairs like {@code \"} to the 2nd character in
* each sequence. Returns the unescaped string, or null if the buffer isn't prefixed with a
* double-quoted string.
*/
private static String readQuotedString(Buffer buffer) {
if (buffer.readByte() != '\"') throw new IllegalArgumentException();
Buffer result = new Buffer();
while (true) {
long i = buffer.indexOfElement(QUOTED_STRING_DELIMITERS);
if (i == -1L) return null; // Unterminated quoted string.
if (buffer.getByte(i) == '"') {
result.write(buffer, i);
buffer.readByte(); // Consume '"'.
return result.readUtf8();
}
if (buffer.size() == i + 1L) return null; // Dangling escape.
result.write(buffer, i);
buffer.readByte(); // Consume '\'.
result.write(buffer, 1L); // The escaped character.
}
}
代码示例来源:origin: square/moshi
if (buffer.getByte(index) == '\\') {
if (builder == null) builder = new StringBuilder();
builder.append(buffer.readUtf8(index));
代码示例来源: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/okio
@Test public void byteAt() {
Buffer buffer = new Buffer();
buffer.writeUtf8("a");
buffer.writeUtf8(repeat('b', SEGMENT_SIZE));
buffer.writeUtf8("c");
assertEquals('a', buffer.getByte(0));
assertEquals('a', buffer.getByte(0)); // getByte doesn't mutate!
assertEquals('c', buffer.getByte(buffer.size() - 1));
assertEquals('b', buffer.getByte(buffer.size() - 2));
assertEquals('b', buffer.getByte(buffer.size() - 3));
}
代码示例来源:origin: square/okhttp
if (skipWhitespaceAndCommas(header)) return; // Unexpected ','.
String parameterValue = !header.exhausted() && header.getByte(0) == '"'
? readQuotedString(header)
: readToken(header);
代码示例来源: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: com.squareup.okhttp3/okhttp
/**
* Reads a double-quoted string, unescaping quoted pairs like {@code \"} to the 2nd character in
* each sequence. Returns the unescaped string, or null if the buffer isn't prefixed with a
* double-quoted string.
*/
private static String readQuotedString(Buffer buffer) {
if (buffer.readByte() != '\"') throw new IllegalArgumentException();
Buffer result = new Buffer();
while (true) {
long i = buffer.indexOfElement(QUOTED_STRING_DELIMITERS);
if (i == -1L) return null; // Unterminated quoted string.
if (buffer.getByte(i) == '"') {
result.write(buffer, i);
buffer.readByte(); // Consume '"'.
return result.readUtf8();
}
if (buffer.size() == i + 1L) return null; // Dangling escape.
result.write(buffer, i);
buffer.readByte(); // Consume '\'.
result.write(buffer, 1L); // The escaped character.
}
}
代码示例来源:origin: square/moshi
int c = buffer.getByte(p++);
if (c == '\n' || c == ' ' || c == '\r' || c == '\t') {
continue;
byte peek = buffer.getByte(1);
switch (peek) {
case '*':
代码示例来源:origin: square/okhttp
switch (source.getBuffer().getByte(0)) {
case '\r':
case '\n':
代码示例来源:origin: square/moshi
byte c = buffer.getByte(i);
result <<= 4;
if (c >= '0' && c <= '9') {
内容来源于网络,如有侵权,请联系作者删除!