本文整理了Java中java.net.ProtocolException
类的一些代码示例,展示了ProtocolException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ProtocolException
类的具体详情如下:
包路径:java.net.ProtocolException
类名称:ProtocolException
[英]Signals that either a connection attempt to a socket of the wrong type, the application of an unsupported operation or that a general error in the underlying protocol has occurred.
[中]表示连接试图连接到错误类型的套接字、应用了不受支持的操作或基础协议中发生了一般性错误。
代码示例来源:origin: prestodb/presto
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();
代码示例来源:origin: com.squareup.okhttp/okhttp-ws
@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;
}
代码示例来源:origin: square/wire
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();
代码示例来源:origin: com.github.ljun20160606/okhttp
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));
代码示例来源:origin: square/wire
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);
代码示例来源:origin: square/okhttp
@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;
}
代码示例来源:origin: javaee/grizzly
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();
}
}
代码示例来源:origin: square/okhttp
/**
* 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));
}
}
}
}
代码示例来源:origin: square/okhttp
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.");
代码示例来源:origin: square/okio
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();
代码示例来源:origin: square/wire
/** 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");
}
代码示例来源:origin: square/okhttp
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);
}
}
代码示例来源:origin: square/wire
/** 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;
}
代码示例来源:origin: square/wire
/** 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;
}
代码示例来源:origin: square/wire
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;
}
代码示例来源:origin: square/okhttp
if (source.exhausted()) return false;
throw new ProtocolException("unexpected data");
代码示例来源:origin: vidstige/jadb
handleTcpip(output, command);
} else {
throw new ProtocolException("Unknown command: " + command);
send(output, e.getMessage());
代码示例来源:origin: looly/hutool
this.conn.setRequestMethod(this.method.toString());
} catch (ProtocolException e) {
throw new HttpException(e.getMessage(), e);
代码示例来源:origin: Leaking/WeGit
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;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp-ws
@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;
}
内容来源于网络,如有侵权,请联系作者删除!