当前位置: 首页>>代码示例>>Java>>正文


Java ProtocolException类代码示例

本文整理汇总了Java中java.net.ProtocolException的典型用法代码示例。如果您正苦于以下问题:Java ProtocolException类的具体用法?Java ProtocolException怎么用?Java ProtocolException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProtocolException类属于java.net包,在下文中一共展示了ProtocolException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: read

import java.net.ProtocolException; //导入依赖的package包/类
@Override
public void read(DataInputStream in) throws IOException {
    final int version = in.readInt();
    switch (version) {
        case VERSION_INIT:
            throw new ProtocolException("Ignored upgrade");
        case VERSION_SPLIT_URI:
            authority = DurableUtils.readNullableString(in);
            documentId = DurableUtils.readNullableString(in);
            mimeType = DurableUtils.readNullableString(in);
            displayName = DurableUtils.readNullableString(in);
            lastModified = in.readLong();
            flags = in.readInt();
            summary = DurableUtils.readNullableString(in);
            size = in.readLong();
            icon = in.readInt();
            path = DurableUtils.readNullableString(in);
            deriveFields();
            break;
        default:
            throw new ProtocolException("Unknown version " + version);
    }
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:24,代码来源:DocumentInfo.java

示例2: a

import java.net.ProtocolException; //导入依赖的package包/类
void a(byte[] bArr) throws IOException {
    if (bArr != null) {
        ByteBuffer wrap = ByteBuffer.wrap(bArr);
        int length = ApkExternalInfoTool.b.getBytes().length;
        byte[] bArr2 = new byte[length];
        wrap.get(bArr2);
        if (!ApkExternalInfoTool.b.equals(new ZipShort(bArr2))) {
            throw new ProtocolException("unknow protocl [" + Arrays.toString(bArr) + "]");
        } else if (bArr.length - length > 2) {
            bArr2 = new byte[2];
            wrap.get(bArr2);
            int value = new ZipShort(bArr2).getValue();
            if ((bArr.length - length) - 2 >= value) {
                byte[] bArr3 = new byte[value];
                wrap.get(bArr3);
                this.a.load(new ByteArrayInputStream(bArr3));
                length = ((bArr.length - length) - value) - 2;
                if (length > 0) {
                    this.b = new byte[length];
                    wrap.get(this.b);
                }
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:26,代码来源:ApkExternalInfoTool.java

示例3: read

import java.net.ProtocolException; //导入依赖的package包/类
@Override
public void read(DataInputStream in) throws IOException {
    final int version = in.readInt();
    switch (version) {
        case VERSION_DROP_TYPE:
            authority = DurableUtils.readNullableString(in);
            rootId = DurableUtils.readNullableString(in);
            flags = in.readInt();
            icon = in.readInt();
            title = DurableUtils.readNullableString(in);
            summary = DurableUtils.readNullableString(in);
            documentId = DurableUtils.readNullableString(in);
            availableBytes = in.readLong();
            totalBytes = in.readLong();
            mimeTypes = DurableUtils.readNullableString(in);
            path = DurableUtils.readNullableString(in);
            deriveFields();
            break;
        default:
            throw new ProtocolException("Unknown version " + version);
    }
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:23,代码来源:RootInfo.java

示例4: readChunkSize

import java.net.ProtocolException; //导入依赖的package包/类
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;
    HttpHeaders.receiveHeaders(client.cookieJar(), url, readHeaders());
    endOfInput(true);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:Http1Codec.java

示例5: checkResponse

import java.net.ProtocolException; //导入依赖的package包/类
void checkResponse(Response response) throws ProtocolException {
  if (response.code() != 101) {
    throw new ProtocolException("Expected HTTP 101 response but was '"
        + response.code() + " " + response.message() + "'");
  }

  String headerConnection = response.header("Connection");
  if (!"Upgrade".equalsIgnoreCase(headerConnection)) {
    throw new ProtocolException("Expected 'Connection' header value 'Upgrade' but was '"
        + headerConnection + "'");
  }

  String headerUpgrade = response.header("Upgrade");
  if (!"websocket".equalsIgnoreCase(headerUpgrade)) {
    throw new ProtocolException(
        "Expected 'Upgrade' header value 'websocket' but was '" + headerUpgrade + "'");
  }

  String headerAccept = response.header("Sec-WebSocket-Accept");
  String acceptExpected = ByteString.encodeUtf8(key + WebSocketProtocol.ACCEPT_MAGIC)
      .sha1().base64();
  if (!acceptExpected.equals(headerAccept)) {
    throw new ProtocolException("Expected 'Sec-WebSocket-Accept' header value '"
        + acceptExpected + "' but was '" + headerAccept + "'");
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:RealWebSocket.java

示例6: testWriteLessThanContentLength

import java.net.ProtocolException; //导入依赖的package包/类
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testWriteLessThanContentLength()
        throws Exception {
    URL url = new URL(NativeTestServer.getEchoBodyURL());
    HttpURLConnection connection =
            (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    // Set a content length that's 1 byte more.
    connection.setRequestProperty(
            "Content-Length", Integer.toString(TestUtil.UPLOAD_DATA.length + 1));
    OutputStream out = connection.getOutputStream();
    out.write(TestUtil.UPLOAD_DATA);
    try {
        connection.getResponseCode();
        fail();
    } catch (ProtocolException e) {
        // Expected.
    }
    connection.disconnect();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:24,代码来源:CronetBufferedOutputStreamTest.java

示例7: connectTunnel

import java.net.ProtocolException; //导入依赖的package包/类
/**
 * Does all the work to build an HTTPS connection over a proxy tunnel. The catch here is that a
 * proxy server can issue an auth challenge and then close the connection.
 */
private void connectTunnel(int connectTimeout, int readTimeout, int writeTimeout)
    throws IOException {
  Request tunnelRequest = createTunnelRequest();
  HttpUrl url = tunnelRequest.url();
  int attemptedConnections = 0;
  int maxAttempts = 21;
  while (true) {
    if (++attemptedConnections > maxAttempts) {
      throw new ProtocolException("Too many tunnel connections attempted: " + maxAttempts);
    }

    connectSocket(connectTimeout, readTimeout);
    tunnelRequest = createTunnel(readTimeout, writeTimeout, tunnelRequest, url);

    if (tunnelRequest == null) break; // Tunnel successfully created.

    // The proxy decided to close the connection after an auth challenge. We need to create a new
    // connection, but this time with the auth credentials.
    closeQuietly(rawSocket);
    rawSocket = null;
    sink = null;
    source = null;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:RealConnection.java

示例8: tooManyProxyAuthFailuresWithConnectionClose

import java.net.ProtocolException; //导入依赖的package包/类
@Test public void tooManyProxyAuthFailuresWithConnectionClose() throws IOException {
  server.useHttps(sslClient.socketFactory, true);
  server.setProtocols(Collections.singletonList(Protocol.HTTP_1_1));
  for (int i = 0; i < 21; i++) {
    server.enqueue(new MockResponse()
        .setResponseCode(407)
        .addHeader("Proxy-Authenticate: Basic realm=\"localhost\"")
        .addHeader("Connection: close"));
  }

  client = client.newBuilder()
      .sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
      .proxy(server.toProxyAddress())
      .proxyAuthenticator(new RecordingOkAuthenticator("password"))
      .hostnameVerifier(new RecordingHostnameVerifier())
      .build();

  Request request = new Request.Builder()
      .url("https://android.com/foo")
      .build();
  try {
    client.newCall(request).execute();
    fail();
  } catch (ProtocolException expected) {
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:CallTest.java

示例9: closeReservedSetThrows

import java.net.ProtocolException; //导入依赖的package包/类
@Test public void closeReservedSetThrows() throws IOException {
  data.write(ByteString.decodeHex("880203ec")); // Close with code 1004
  data.write(ByteString.decodeHex("880203ed")); // Close with code 1005
  data.write(ByteString.decodeHex("880203ee")); // Close with code 1006
  for (int i = 1012; i <= 2999; i++) {
    data.write(ByteString.decodeHex("8802" + Util.format("%04X", i))); // Close with code 'i'
  }

  int count = 0;
  for (; !data.exhausted(); count++) {
    try {
      clientReader.processNextFrame();
      fail();
    } catch (ProtocolException e) {
      String message = e.getMessage();
      assertTrue(message, Pattern.matches("Code \\d+ is reserved and may not be used.", message));
    }
  }
  assertEquals(1991, count);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:WebSocketReaderTest.java

示例10: testOnPingIncorrect

import java.net.ProtocolException; //导入依赖的package包/类
public void testOnPingIncorrect(boolean fin, boolean rsv1, boolean rsv2,
                                boolean rsv3, ByteBuffer data) {
    if (fin && !rsv1 && !rsv2 && !rsv3 && data.remaining() <= 125) {
        throw new SkipException("Correct frame");
    }
    CompletableFuture<WebSocket> webSocket = new CompletableFuture<>();
    MockChannel channel = new MockChannel.Builder()
            .provideFrame(fin, rsv1, rsv2, rsv3, Opcode.PING, data)
            .expectClose((code, reason) ->
                    Integer.valueOf(1002).equals(code) && "".equals(reason))
            .build();
    MockListener listener = new MockListener.Builder()
            .expectOnOpen((ws) -> true)
            .expectOnError((ws, error) -> error instanceof ProtocolException)
            .build();
    webSocket.complete(newWebSocket(channel, listener));
    checkExpectations(500, TimeUnit.MILLISECONDS, channel, listener);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PingTest.java

示例11: getOutputStream

import java.net.ProtocolException; //导入依赖的package包/类
@Override public OutputStream getOutputStream() throws IOException {
  OutputStreamRequestBody requestBody = (OutputStreamRequestBody) buildCall().request().body();
  if (requestBody == null) {
    throw new ProtocolException("method does not support a request body: " + method);
  }

  // If this request needs to stream bytes to the server, build a physical connection immediately
  // and start streaming those bytes over that connection.
  if (requestBody instanceof StreamedRequestBody) {
    connect();
    networkInterceptor.proceed();
  }

  if (requestBody.isClosed()) {
    throw new ProtocolException("cannot write request body after response has been read");
  }

  return requestBody.outputStream();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:OkHttpURLConnection.java

示例12: contentDisagreesWithChunkedHeaderBodyTooShort

import java.net.ProtocolException; //导入依赖的package包/类
@Test public void contentDisagreesWithChunkedHeaderBodyTooShort() throws IOException {
  MockResponse mockResponse = new MockResponse();
  mockResponse.setChunkedBody("abcde", 5);

  Buffer truncatedBody = new Buffer();
  Buffer fullBody = mockResponse.getBody();
  truncatedBody.write(fullBody, fullBody.indexOf((byte) 'e'));
  mockResponse.setBody(truncatedBody);

  mockResponse.clearHeaders();
  mockResponse.addHeader("Transfer-encoding: chunked");
  mockResponse.setSocketPolicy(DISCONNECT_AT_END);

  server.enqueue(mockResponse);

  try {
    readAscii(urlFactory.open(server.url("/").url()).getInputStream(), 5);
    fail();
  } catch (ProtocolException expected) {
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:URLConnectionTest.java

示例13: doesNotFollow21Redirects

import java.net.ProtocolException; //导入依赖的package包/类
@Test public void doesNotFollow21Redirects() throws Exception {
  for (int i = 0; i < 21; i++) {
    server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
        .addHeader("Location: /" + (i + 1))
        .setBody("Redirecting to /" + (i + 1)));
  }

  connection = urlFactory.open(server.url("/0").url());
  try {
    connection.getInputStream();
    fail();
  } catch (ProtocolException expected) {
    assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
    assertEquals("Too many follow-up requests: 21", expected.getMessage());
    assertEquals(server.url("/20").url(), connection.getURL());
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:URLConnectionTest.java

示例14: doesNotAttemptAuthorization21Times

import java.net.ProtocolException; //导入依赖的package包/类
@Test public void doesNotAttemptAuthorization21Times() throws Exception {
  for (int i = 0; i < 21; i++) {
    server.enqueue(new MockResponse().setResponseCode(401));
  }

  String credential = Credentials.basic("jesse", "peanutbutter");
  urlFactory.setClient(urlFactory.client().newBuilder()
      .authenticator(new RecordingOkAuthenticator(credential))
      .build());

  connection = urlFactory.open(server.url("/").url());
  try {
    connection.getInputStream();
    fail();
  } catch (ProtocolException expected) {
    assertEquals(401, connection.getResponseCode());
    assertEquals("Too many follow-up requests: 21", expected.getMessage());
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:URLConnectionTest.java

示例15: read

import java.net.ProtocolException; //导入依赖的package包/类
@Override
public void read(DataInputStream in) throws IOException {
    final int version = in.readInt();
    switch (version) {
        case VERSION_INIT:
            throw new ProtocolException("Ignored upgrade");
        case VERSION_ADD_ROOT:
            if (in.readBoolean()) {
                root = new RootInfo();
                root.read(in);
            }
            final int size = in.readInt();
            for (int i = 0; i < size; i++) {
                final DocumentInfo doc = new DocumentInfo();
                doc.read(in);
                add(doc);
            }
            break;
        default:
            throw new ProtocolException("Unknown version " + version);
    }
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:23,代码来源:DocumentStack.java


注:本文中的java.net.ProtocolException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。