本文整理了Java中okio.BufferedSource.readByte()
方法的一些代码示例,展示了BufferedSource.readByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedSource.readByte()
方法的具体详情如下:
包路径:okio.BufferedSource
类名称:BufferedSource
方法名:readByte
[英]Removes a byte from this source and returns it.
[中]从此源中删除一个字节并返回它。
代码示例来源:origin: square/okhttp
static int readMedium(BufferedSource source) throws IOException {
return (source.readByte() & 0xff) << 16
| (source.readByte() & 0xff) << 8
| (source.readByte() & 0xff);
}
代码示例来源:origin: square/okhttp
private int readByte() throws IOException {
return source.readByte() & 0xff;
}
代码示例来源:origin: square/okhttp
private void readContinuationHeader() throws IOException {
int previousStreamId = streamId;
length = left = readMedium(source);
byte type = (byte) (source.readByte() & 0xff);
flags = (byte) (source.readByte() & 0xff);
if (logger.isLoggable(FINE)) logger.fine(frameLog(true, streamId, length, type, flags));
streamId = (source.readInt() & 0x7fffffff);
if (type != TYPE_CONTINUATION) throw ioException("%s != TYPE_CONTINUATION", type);
if (streamId != previousStreamId) throw ioException("TYPE_CONTINUATION streamId changed");
}
}
代码示例来源:origin: square/okhttp
private void readPriority(Handler handler, int streamId) throws IOException {
int w1 = source.readInt();
boolean exclusive = (w1 & 0x80000000) != 0;
int streamDependency = (w1 & 0x7fffffff);
int weight = (source.readByte() & 0xff) + 1;
handler.priority(streamId, streamDependency, weight, exclusive);
}
代码示例来源: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/okhttp
private void readPushPromise(Handler handler, int length, byte flags, int streamId)
throws IOException {
if (streamId == 0) {
throw ioException("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0");
}
short padding = (flags & FLAG_PADDED) != 0 ? (short) (source.readByte() & 0xff) : 0;
int promisedStreamId = source.readInt() & 0x7fffffff;
length -= 4; // account for above read.
length = lengthWithoutPadding(length, flags, padding);
List<Header> headerBlock = readHeaderBlock(length, padding, flags, streamId);
handler.pushPromise(streamId, promisedStreamId, headerBlock);
}
代码示例来源:origin: square/okhttp
private void readHeaders(Handler handler, int length, byte flags, int streamId)
throws IOException {
if (streamId == 0) throw ioException("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0");
boolean endStream = (flags & FLAG_END_STREAM) != 0;
short padding = (flags & FLAG_PADDED) != 0 ? (short) (source.readByte() & 0xff) : 0;
if ((flags & FLAG_PRIORITY) != 0) {
readPriority(handler, streamId);
length -= 5; // account for above read.
}
length = lengthWithoutPadding(length, flags, padding);
List<Header> headerBlock = readHeaderBlock(length, padding, flags, streamId);
handler.headers(endStream, streamId, -1, headerBlock);
}
代码示例来源:origin: square/okhttp
private void readData(Handler handler, int length, byte flags, int streamId)
throws IOException {
if (streamId == 0) throw ioException("PROTOCOL_ERROR: TYPE_DATA streamId == 0");
// TODO: checkState open or half-closed (local) or raise STREAM_CLOSED
boolean inFinished = (flags & FLAG_END_STREAM) != 0;
boolean gzipped = (flags & FLAG_COMPRESSED) != 0;
if (gzipped) {
throw ioException("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA");
}
short padding = (flags & FLAG_PADDED) != 0 ? (short) (source.readByte() & 0xff) : 0;
length = lengthWithoutPadding(length, flags, padding);
handler.data(inFinished, streamId, source, length);
source.skip(padding);
}
代码示例来源:origin: square/okio
@Test public void readByteTooShortThrows() throws IOException {
try {
source.readByte();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okhttp
int b = source.readByte() & 0xff;
if (b == 0x80) { // 10000000
throw new IOException("index == 0");
代码示例来源:origin: square/okio
@Test public void gunzipExhaustsSource() throws Exception {
Buffer gzippedSource = new Buffer()
.write(ByteString.decodeHex("1f8b08000000000000004b4c4a0600c241243503000000")); // 'abc'
ExhaustableSource exhaustableSource = new ExhaustableSource(gzippedSource);
BufferedSource gunzippedSource = Okio.buffer(new GzipSource(exhaustableSource));
assertEquals('a', gunzippedSource.readByte());
assertEquals('b', gunzippedSource.readByte());
assertEquals('c', gunzippedSource.readByte());
assertFalse(exhaustableSource.exhausted);
assertEquals(-1, gunzippedSource.read(new Buffer(), 1));
assertTrue(exhaustableSource.exhausted);
}
代码示例来源:origin: square/okio
@Test public void readBytes() throws Exception {
sink.write(new byte[] { (byte) 0xab, (byte) 0xcd });
sink.emit();
assertEquals(0xab, source.readByte() & 0xff);
assertEquals(0xcd, source.readByte() & 0xff);
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void readIntTooShortThrows() throws IOException {
sink.writeInt(Integer.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readInt();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void readLongTooShortThrows() throws IOException {
sink.writeLong(Long.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readLong();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void readIntLeTooShortThrows() throws IOException {
sink.writeIntLe(Integer.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readIntLe();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void readShortTooShortThrows() throws IOException {
sink.writeShort(Short.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readShort();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void readShortLeTooShortThrows() throws IOException {
sink.writeShortLe(Short.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readShortLe();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void readLongLeTooShortThrows() throws IOException {
sink.writeLongLe(Long.MAX_VALUE);
sink.emit();
source.readByte();
try {
source.readLongLe();
fail();
} catch (EOFException expected) {
}
}
代码示例来源:origin: square/okio
@Test public void skip() throws Exception {
sink.writeUtf8("a");
sink.writeUtf8(repeat('b', SEGMENT_SIZE));
sink.writeUtf8("c");
sink.emit();
source.skip(1);
assertEquals('b', source.readByte() & 0xff);
source.skip(SEGMENT_SIZE - 2);
assertEquals('b', source.readByte() & 0xff);
source.skip(1);
assertTrue(source.exhausted());
}
代码示例来源:origin: square/okio
@Test public void select() throws IOException {
Options options = Options.Companion.of(
ByteString.encodeUtf8("ROCK"),
ByteString.encodeUtf8("SCISSORS"),
ByteString.encodeUtf8("PAPER"));
sink.writeUtf8("PAPER,SCISSORS,ROCK");
sink.emit();
assertEquals(2, source.select(options));
assertEquals(',', source.readByte());
assertEquals(1, source.select(options));
assertEquals(',', source.readByte());
assertEquals(0, source.select(options));
assertTrue(source.exhausted());
}
内容来源于网络,如有侵权,请联系作者删除!