本文整理汇总了Java中com.squareup.okhttp.internal.Util.skipByReading方法的典型用法代码示例。如果您正苦于以下问题:Java Util.skipByReading方法的具体用法?Java Util.skipByReading怎么用?Java Util.skipByReading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.internal.Util
的用法示例。
在下文中一共展示了Util.skipByReading方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: data
import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
@Override public void data(boolean inFinished, int streamId, InputStream in, int length)
throws IOException {
SpdyStream dataStream = getStream(streamId);
if (dataStream == null) {
writeSynResetLater(streamId, ErrorCode.INVALID_STREAM);
Util.skipByReading(in, length);
return;
}
dataStream.receiveData(in, length);
if (inFinished) {
dataStream.receiveFin();
}
}
示例2: readGoAway
import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
private void readGoAway(Handler handler, int flags, int length, int streamId)
throws IOException {
if (length < 8) throw ioException("TYPE_GOAWAY length < 8: %s", length);
int lastStreamId = in.readInt();
int errorCodeInt = in.readInt();
int opaqueDataLength = length - 8;
ErrorCode errorCode = ErrorCode.fromHttp2(errorCodeInt);
if (errorCode == null) {
throw ioException("TYPE_RST_STREAM unexpected error code: %d", errorCodeInt);
}
if (Util.skipByReading(in, opaqueDataLength) != opaqueDataLength) {
throw new IOException("TYPE_GOAWAY opaque data was truncated");
}
handler.goAway(lastStreamId, errorCode);
}
示例3: receive
import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
void receive(InputStream in, int byteCount) throws IOException {
assert (!Thread.holdsLock(SpdyStream.this));
if (byteCount == 0) {
return;
}
int pos;
int limit;
int firstNewByte;
boolean finished;
boolean flowControlError;
synchronized (SpdyStream.this) {
finished = this.finished;
pos = this.pos;
firstNewByte = this.limit;
limit = this.limit;
flowControlError = byteCount > buffer.length - available();
}
// If the peer sends more data than we can handle, discard it and close the connection.
if (flowControlError) {
Util.skipByReading(in, byteCount);
closeLater(ErrorCode.FLOW_CONTROL_ERROR);
return;
}
// Discard data received after the stream is finished. It's probably a benign race.
if (finished) {
Util.skipByReading(in, byteCount);
return;
}
// Fill the buffer without holding any locks. First fill [limit..buffer.length) if that
// won't overwrite unread data. Then fill [limit..pos). We can't hold a lock, otherwise
// writes will be blocked until reads complete.
if (pos < limit) {
int firstCopyCount = Math.min(byteCount, buffer.length - limit);
Util.readFully(in, buffer, limit, firstCopyCount);
limit += firstCopyCount;
byteCount -= firstCopyCount;
if (limit == buffer.length) {
limit = 0;
}
}
if (byteCount > 0) {
Util.readFully(in, buffer, limit, byteCount);
limit += byteCount;
}
synchronized (SpdyStream.this) {
// Update the new limit, and mark the position as readable if necessary.
this.limit = limit;
if (this.pos == -1) {
this.pos = firstNewByte;
SpdyStream.this.notifyAll();
}
}
}
示例4: nextFrame
import com.squareup.okhttp.internal.Util; //导入方法依赖的package包/类
/**
* Send the next frame to {@code handler}. Returns true unless there are no
* more frames on the stream.
*/
@Override public boolean nextFrame(Handler handler) throws IOException {
int w1;
try {
w1 = in.readInt();
} catch (IOException e) {
return false; // This might be a normal socket close.
}
int w2 = in.readInt();
boolean control = (w1 & 0x80000000) != 0;
int flags = (w2 & 0xff000000) >>> 24;
int length = (w2 & 0xffffff);
if (control) {
int version = (w1 & 0x7fff0000) >>> 16;
int type = (w1 & 0xffff);
if (version != 3) {
throw new ProtocolException("version != 3: " + version);
}
switch (type) {
case TYPE_SYN_STREAM:
readSynStream(handler, flags, length);
return true;
case TYPE_SYN_REPLY:
readSynReply(handler, flags, length);
return true;
case TYPE_RST_STREAM:
readRstStream(handler, flags, length);
return true;
case TYPE_SETTINGS:
readSettings(handler, flags, length);
return true;
case TYPE_NOOP:
if (length != 0) throw ioException("TYPE_NOOP length: %d != 0", length);
handler.noop();
return true;
case TYPE_PING:
readPing(handler, flags, length);
return true;
case TYPE_GOAWAY:
readGoAway(handler, flags, length);
return true;
case TYPE_HEADERS:
readHeaders(handler, flags, length);
return true;
case TYPE_WINDOW_UPDATE:
readWindowUpdate(handler, flags, length);
return true;
case TYPE_CREDENTIAL:
Util.skipByReading(in, length);
throw new UnsupportedOperationException("TODO"); // TODO: implement
default:
throw new IOException("Unexpected frame");
}
} else {
int streamId = w1 & 0x7fffffff;
boolean inFinished = (flags & FLAG_FIN) != 0;
handler.data(inFinished, streamId, in, length);
return true;
}
}