Refine search
throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); toRead = Math.min(toRead, maskBuffer.length); read = source.read(maskBuffer, 0, (int) toRead); if (read == -1) throw new EOFException(); toggleMask(maskBuffer, read, maskKey, frameBytesRead); sink.write(maskBuffer, 0, (int) read); } else { read = source.read(sink, toRead); if (read == -1) throw new EOFException();
@Override public long read(Buffer sink, long byteCount) throws IOException { if (closed) throw new IOException("closed"); if (messageClosed) throw new IllegalStateException("closed"); if (frameBytesRead == frameLength) { if (isFinalFrame) return -1; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } if (isFinalFrame && frameLength == 0) { return -1; // Fast-path for empty final frame. } } long toRead = Math.min(byteCount, frameLength - frameBytesRead); long read; if (isMasked) { toRead = Math.min(toRead, maskBuffer.length); read = source.read(maskBuffer, 0, (int) toRead); if (read == -1) throw new EOFException(); toggleMask(maskBuffer, read, maskKey, frameBytesRead); sink.write(maskBuffer, 0, (int) read); } else { read = source.read(sink, toRead); if (read == -1) throw new EOFException(); } frameBytesRead += read; return read; }
while (pos < limit && !source.exhausted()) { int tagAndFieldEncoding = internalReadVarint32(); if (tagAndFieldEncoding == 0) throw new ProtocolException("Unexpected tag 0"); int tag = tagAndFieldEncoding >> TAG_FIELD_ENCODING_BITS; int groupOrFieldEncoding = tagAndFieldEncoding & FIELD_ENCODING_MASK; case STATE_END_GROUP: if (tag == expectedEndTag) return; // Success! throw new ProtocolException("Unexpected end group"); case STATE_LENGTH_DELIMITED: int length = internalReadVarint32(); pos += length; source.skip(length); break; case STATE_VARINT: break; default: throw new ProtocolException("Unexpected field encoding: " + groupOrFieldEncoding); throw new EOFException();
if (frameBytesRead < frameLength) { if (isClient) { source.readFully(buffer, frameLength); } else { while (frameBytesRead < frameLength) { int toRead = (int) Math.min(frameLength - frameBytesRead, maskBuffer.length); int read = source.read(maskBuffer, 0, toRead); if (read == -1) throw new EOFException(); toggleMask(maskBuffer, read, maskKey, frameBytesRead); buffer.write(maskBuffer, 0, read); long bufferSize = buffer.size(); if (bufferSize == 1) { throw new ProtocolException("Malformed close payload length of 1."); } else if (bufferSize != 0) { code = buffer.readShort(); reason = buffer.readUtf8(); String codeExceptionMessage = WebSocketProtocol.closeCodeExceptionMessage(code); if (codeExceptionMessage != null) throw new ProtocolException(codeExceptionMessage); break; default: throw new ProtocolException("Unknown control opcode: " + toHexString(opcode));
while (pos < limit && !source.exhausted()) { int tagAndFieldEncoding = internalReadVarint32(); if (tagAndFieldEncoding == 0) throw new ProtocolException("Unexpected tag 0"); throw new ProtocolException("Unexpected end group"); state = STATE_LENGTH_DELIMITED; int length = internalReadVarint32(); if (length < 0) throw new ProtocolException("Negative length: " + length); if (pushedLimit != -1) throw new IllegalStateException(); if (limit > pushedLimit) throw new EOFException(); return tag; throw new ProtocolException("Unexpected field encoding: " + groupOrFieldEncoding);
@Override public void setRequestMethod(String method) throws ProtocolException { if (!METHODS.contains(method)) { throw new ProtocolException("Expected one of " + METHODS + " but was " + method); } this.method = method; }
private void resumeLiteralWithIndexing(Buffer input, DecodingCallback action) { if (!completeReading(input)) { return; } try { // // 1. (name, value) will be stored in the table as strings // 2. Most likely the callback will also create strings from them // ------------------------------------------------------------------------ // Let's create those string beforehand (and only once!) to benefit everyone // String n; String v = value.toString(); if (firstValueIndex) { HeaderTable.HeaderField f = table.get(intValue); n = f.name; action.onLiteralWithIndexing(intValue, n, v, valueHuffmanEncoded); } else { n = name.toString(); action.onLiteralWithIndexing(n, nameHuffmanEncoded, v, valueHuffmanEncoded); } table.put(n, v); } catch (IllegalArgumentException | IllegalStateException e) { throw new RuntimeException( new ProtocolException().initCause(e)); } finally { cleanUpAfterReading(); } }
/** * Reads a message body into across one or more frames. Control frames that occur between * fragments will be processed. If the message payload is masked this will unmask as it's being * processed. */ private void readMessage() throws IOException { while (true) { if (closed) throw new IOException("closed"); if (frameLength > 0) { source.readFully(messageFrameBuffer, frameLength); if (!isClient) { messageFrameBuffer.readAndWriteUnsafe(maskCursor); maskCursor.seek(messageFrameBuffer.size() - frameLength); toggleMask(maskCursor, maskKey); maskCursor.close(); } } if (isFinalFrame) break; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } } } }
long timeoutBefore = source.timeout().timeoutNanos(); source.timeout().clearTimeout(); try { b0 = source.readByte() & 0xff; } finally { source.timeout().timeout(timeoutBefore, TimeUnit.NANOSECONDS); throw new ProtocolException("Control frames must be final."); if (reservedFlag1 || reservedFlag2 || reservedFlag3) { throw new ProtocolException("Reserved flags are unsupported."); if (isMasked == isClient) { throw new ProtocolException(isClient ? "Server-sent frames must not be masked." : "Client-sent frames must be masked."); frameLength = source.readLong(); if (frameLength < 0) { throw new ProtocolException( "Frame length 0x" + Long.toHexString(frameLength) + " > 0x7FFFFFFFFFFFFFFF"); throw new ProtocolException("Control frame must be less than " + PAYLOAD_BYTE_MAX + "B.");
int socksVersion = fromSource.readByte() & 0xff; if (socksVersion != VERSION_5) throw new ProtocolException(); int methodCount = fromSource.readByte() & 0xff; boolean foundSupportedMethod = false; for (int i = 0; i < methodCount; i++) { int method = fromSource.readByte() & 0xff; foundSupportedMethod |= method == METHOD_NO_AUTHENTICATION_REQUIRED; if (!foundSupportedMethod) throw new ProtocolException(); int reserved = fromSource.readByte() & 0xff; if (version != VERSION_5 || command != COMMAND_CONNECT || reserved != 0) { throw new ProtocolException(); inetAddress = InetAddress.getByName(fromSource.readUtf8(domainNameLength)); } else { throw new ProtocolException(); int port = fromSource.readShort() & 0xffff; openSockets.add(toSocket); byte[] localAddress = toSocket.getLocalAddress().getAddress(); if (localAddress.length != 4) throw new ProtocolException();
/** Reads a raw varint up to 64 bits in length from the stream. */ public long readVarint64() throws IOException { if (state != STATE_VARINT && state != STATE_LENGTH_DELIMITED) { throw new ProtocolException("Expected VARINT or LENGTH_DELIMITED but was " + state); } int shift = 0; long result = 0; while (shift < 64) { source.require(1); // Throws EOFException if insufficient bytes are available. pos++; byte b = source.readByte(); result |= (long) (b & 0x7F) << shift; if ((b & 0x80) == 0) { afterPackableScalar(STATE_VARINT); return result; } shift += 7; } throw new ProtocolException("WireInput encountered a malformed varint"); }
private void readChunkSize() throws IOException { // Read the suffix of the previous chunk. if (bytesRemainingInChunk != NO_CHUNK_YET) { source.readUtf8LineStrict(); } try { bytesRemainingInChunk = source.readHexadecimalUnsignedLong(); String extensions = source.readUtf8LineStrict().trim(); if (bytesRemainingInChunk < 0 || (!extensions.isEmpty() && !extensions.startsWith(";"))) { throw new ProtocolException("expected chunk size and optional extensions but was \"" + bytesRemainingInChunk + extensions + "\""); } } catch (NumberFormatException e) { throw new ProtocolException(e.getMessage()); } if (bytesRemainingInChunk == 0L) { hasMoreChunks = false; trailers = readHeaders(); HttpHeaders.receiveHeaders(client.cookieJar(), url, trailers); endOfInput(true, null); } }
/** Reads a 32-bit little-endian integer from the stream. */ public int readFixed32() throws IOException { if (state != STATE_FIXED32 && state != STATE_LENGTH_DELIMITED) { throw new ProtocolException("Expected FIXED32 or LENGTH_DELIMITED but was " + state); } source.require(4); // Throws EOFException if insufficient bytes are available. pos += 4; int result = source.readIntLe(); afterPackableScalar(STATE_FIXED32); return result; }
/** Reads a 64-bit little-endian integer from the stream. */ public long readFixed64() throws IOException { if (state != STATE_FIXED64 && state != STATE_LENGTH_DELIMITED) { throw new ProtocolException("Expected FIXED64 or LENGTH_DELIMITED but was " + state); } source.require(8); // Throws EOFException if insufficient bytes are available. pos += 8; long result = source.readLongLe(); afterPackableScalar(STATE_FIXED64); return result; }
private long beforeLengthDelimitedScalar() throws IOException { if (state != STATE_LENGTH_DELIMITED) { throw new ProtocolException("Expected LENGTH_DELIMITED but was " + state); } long byteCount = limit - pos; source.require(byteCount); // Throws EOFException if insufficient bytes are available. state = STATE_TAG; // We've completed a length-delimited scalar. Pop the limit. pos = limit; limit = pushedLimit; pushedLimit = -1; return byteCount; }
if (source.exhausted()) return false; throw new ProtocolException("unexpected data");
handleTcpip(output, command); } else { throw new ProtocolException("Unknown command: " + command); send(output, e.getMessage());
this.conn.setRequestMethod(this.method.toString()); } catch (ProtocolException e) { throw new HttpException(e.getMessage(), e);
public HttpKnife put(String url) { try { openConnection(new URL(url)); connection.setRequestMethod(Method.PUT); connection.setDoOutput(true); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } return this; }
@Override public long read(Buffer sink, long byteCount) throws IOException { if (closed) throw new IOException("closed"); if (messageClosed) throw new IllegalStateException("closed"); if (frameBytesRead == frameLength) { if (isFinalFrame) return -1; // We are exhausted and have no continuations. readUntilNonControlFrame(); if (opcode != OPCODE_CONTINUATION) { throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode)); } if (isFinalFrame && frameLength == 0) { return -1; // Fast-path for empty final frame. } } long toRead = Math.min(byteCount, frameLength - frameBytesRead); long read; if (isMasked) { toRead = Math.min(toRead, maskBuffer.length); read = source.read(maskBuffer, 0, (int) toRead); if (read == -1) throw new EOFException(); toggleMask(maskBuffer, read, maskKey, frameBytesRead); sink.write(maskBuffer, 0, (int) read); } else { read = source.read(sink, toRead); if (read == -1) throw new EOFException(); } frameBytesRead += read; return read; }