本文整理匯總了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;
}
}