Java Code Examples for com.squareup.okhttp.internal.Util#skipByReading()
The following examples show how to use
com.squareup.okhttp.internal.Util#skipByReading() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Http20Draft04.java From android-discourse with Apache License 2.0 | 5 votes |
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); }
Example 2
Source File: Http20Draft06.java From reader with MIT License | 5 votes |
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); }
Example 3
Source File: SpdyConnection.java From reader with MIT License | 5 votes |
@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(); } }
Example 4
Source File: SpdyConnection.java From bluemix-parking-meter with MIT License | 5 votes |
@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(); } }
Example 5
Source File: Http20Draft06.java From CordovaYoutubeVideoPlayer with MIT License | 5 votes |
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); }
Example 6
Source File: SpdyConnection.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 5 votes |
@Override public void data(int flags, int streamId, InputStream in, int length) throws IOException { SpdyStream dataStream = getStream(streamId); if (dataStream == null) { writeSynResetLater(streamId, SpdyStream.RST_INVALID_STREAM); Util.skipByReading(in, length); return; } dataStream.receiveData(in, length); if ((flags & SpdyConnection.FLAG_FIN) != 0) { dataStream.receiveFin(); } }
Example 7
Source File: SpdyConnection.java From wildfly-samples with MIT License | 5 votes |
@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(); } }
Example 8
Source File: SpdyConnection.java From CordovaYoutubeVideoPlayer with MIT License | 5 votes |
@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(); } }
Example 9
Source File: Http20Draft06.java From IoTgo_Android_App with MIT License | 5 votes |
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); }
Example 10
Source File: Http20Draft06.java From crosswalk-cordova-android with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: SpdyConnection.java From cordova-android-chromeview with Apache License 2.0 | 5 votes |
@Override public void data(int flags, int streamId, InputStream in, int length) throws IOException { SpdyStream dataStream = getStream(streamId); if (dataStream == null) { writeSynResetLater(streamId, SpdyStream.RST_INVALID_STREAM); Util.skipByReading(in, length); return; } dataStream.receiveData(in, length); if ((flags & SpdyConnection.FLAG_FIN) != 0) { dataStream.receiveFin(); } }
Example 12
Source File: SpdyReader.java From cordova-android-chromeview with Apache License 2.0 | 4 votes |
/** * Send the next frame to {@code handler}. Returns true unless there are no * more frames on the stream. */ 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 SpdyConnection.TYPE_SYN_STREAM: readSynStream(handler, flags, length); return true; case SpdyConnection.TYPE_SYN_REPLY: readSynReply(handler, flags, length); return true; case SpdyConnection.TYPE_RST_STREAM: readRstStream(handler, flags, length); return true; case SpdyConnection.TYPE_SETTINGS: readSettings(handler, flags, length); return true; case SpdyConnection.TYPE_NOOP: if (length != 0) throw ioException("TYPE_NOOP length: %d != 0", length); handler.noop(); return true; case SpdyConnection.TYPE_PING: readPing(handler, flags, length); return true; case SpdyConnection.TYPE_GOAWAY: readGoAway(handler, flags, length); return true; case SpdyConnection.TYPE_HEADERS: readHeaders(handler, flags, length); return true; case SpdyConnection.TYPE_WINDOW_UPDATE: readWindowUpdate(handler, flags, length); return true; case SpdyConnection.TYPE_CREDENTIAL: Util.skipByReading(in, length); throw new UnsupportedOperationException("TODO"); // TODO: implement default: throw new IOException("Unexpected frame"); } } else { int streamId = w1 & 0x7fffffff; handler.data(flags, streamId, in, length); return true; } }
Example 13
Source File: SpdyStream.java From L.TileLayer.Cordova with MIT License | 4 votes |
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(); } } }
Example 14
Source File: Spdy3.java From IoTgo_Android_App with MIT License | 4 votes |
/** * 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; } }
Example 15
Source File: SpdyReader.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 4 votes |
/** * Send the next frame to {@code handler}. Returns true unless there are no * more frames on the stream. */ 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 SpdyConnection.TYPE_SYN_STREAM: readSynStream(handler, flags, length); return true; case SpdyConnection.TYPE_SYN_REPLY: readSynReply(handler, flags, length); return true; case SpdyConnection.TYPE_RST_STREAM: readRstStream(handler, flags, length); return true; case SpdyConnection.TYPE_SETTINGS: readSettings(handler, flags, length); return true; case SpdyConnection.TYPE_NOOP: if (length != 0) throw ioException("TYPE_NOOP length: %d != 0", length); handler.noop(); return true; case SpdyConnection.TYPE_PING: readPing(handler, flags, length); return true; case SpdyConnection.TYPE_GOAWAY: readGoAway(handler, flags, length); return true; case SpdyConnection.TYPE_HEADERS: readHeaders(handler, flags, length); return true; case SpdyConnection.TYPE_WINDOW_UPDATE: readWindowUpdate(handler, flags, length); return true; case SpdyConnection.TYPE_CREDENTIAL: Util.skipByReading(in, length); throw new UnsupportedOperationException("TODO"); // TODO: implement default: throw new IOException("Unexpected frame"); } } else { int streamId = w1 & 0x7fffffff; handler.data(flags, streamId, in, length); return true; } }
Example 16
Source File: SpdyStream.java From IoTgo_Android_App with MIT License | 4 votes |
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(); } } }
Example 17
Source File: SpdyStream.java From crosswalk-cordova-android with Apache License 2.0 | 4 votes |
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(); } } }
Example 18
Source File: SpdyStream.java From reader with MIT License | 4 votes |
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(); } } }
Example 19
Source File: SpdyStream.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 4 votes |
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(SpdyStream.RST_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(); } } }
Example 20
Source File: SpdyStream.java From cordova-android-chromeview with Apache License 2.0 | 4 votes |
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(SpdyStream.RST_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(); } } }