當前位置: 首頁>>代碼示例>>Java>>正文


Java SpdyStream類代碼示例

本文整理匯總了Java中com.squareup.okhttp.internal.spdy.SpdyStream的典型用法代碼示例。如果您正苦於以下問題:Java SpdyStream類的具體用法?Java SpdyStream怎麽用?Java SpdyStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SpdyStream類屬於com.squareup.okhttp.internal.spdy包,在下文中一共展示了SpdyStream類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pushPromises

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
private void pushPromises(SpdyStream stream, List<PushPromise> promises) throws IOException {
  for (PushPromise pushPromise : promises) {
    List<Header> pushedHeaders = new ArrayList<Header>();
    pushedHeaders.add(new Header(stream.getConnection().getProtocol() == Protocol.SPDY_3
        ? Header.TARGET_HOST
        : Header.TARGET_AUTHORITY, getUrl(pushPromise.getPath()).getHost()));
    pushedHeaders.add(new Header(Header.TARGET_METHOD, pushPromise.getMethod()));
    pushedHeaders.add(new Header(Header.TARGET_PATH, pushPromise.getPath()));
    for (int i = 0, size = pushPromise.getHeaders().size(); i < size; i++) {
      String header = pushPromise.getHeaders().get(i);
      String[] headerParts = header.split(":", 2);
      if (headerParts.length != 2) {
        throw new AssertionError("Unexpected header: " + header);
      }
      pushedHeaders.add(new Header(headerParts[0], headerParts[1].trim()));
    }
    String requestLine = pushPromise.getMethod() + ' ' + pushPromise.getPath() + " HTTP/1.1";
    List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
    requestQueue.add(new RecordedRequest(requestLine, pushPromise.getHeaders(), chunkSizes, 0,
        Util.EMPTY_BYTE_ARRAY, sequenceNumber.getAndIncrement(), socket));
    byte[] pushedBody = pushPromise.getResponse().getBody();
    SpdyStream pushedStream =
        stream.getConnection().pushStream(stream.getId(), pushedHeaders, pushedBody.length > 0);
    writeResponse(pushedStream, pushPromise.getResponse());
  }
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:27,代碼來源:MockWebServer.java

示例2: writeResponse

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
private void writeResponse(SpdyStream stream, MockResponse response) throws IOException {
  List<String> spdyHeaders = new ArrayList<String>();
  String[] statusParts = response.getStatus().split(" ", 2);
  if (statusParts.length != 2) {
    throw new AssertionError("Unexpected status: " + response.getStatus());
  }
  spdyHeaders.add(":status");
  spdyHeaders.add(statusParts[1]);
  spdyHeaders.add(":version");
  spdyHeaders.add(statusParts[0]);
  for (String header : response.getHeaders()) {
    String[] headerParts = header.split(":", 2);
    if (headerParts.length != 2) {
      throw new AssertionError("Unexpected header: " + header);
    }
    spdyHeaders.add(headerParts[0].toLowerCase(Locale.US).trim());
    spdyHeaders.add(headerParts[1].trim());
  }
  byte[] body = response.getBody();
  stream.reply(spdyHeaders, body.length > 0);
  if (body.length > 0) {
    stream.getOutputStream().write(body);
    stream.getOutputStream().close();
  }
}
 
開發者ID:c-ong,項目名稱:mirrored-okhttp,代碼行數:26,代碼來源:MockSpdyServer.java

示例3: SpdySource

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
SpdySource(SpdyStream stream, CacheRequest cacheRequest) throws IOException {
  this.stream = stream;
  this.source = stream.getSource();

  // Some apps return a null body; for compatibility we treat that like a null cache request.
  OutputStream cacheBody = cacheRequest != null ? cacheRequest.getBody() : null;
  if (cacheBody == null) {
    cacheRequest = null;
  }

  this.cacheBody = cacheBody;
  this.cacheRequest = cacheRequest;
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:14,代碼來源:SpdyTransport.java

示例4: makeReusable

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
@Override public boolean makeReusable(boolean streamCancelled, OutputStream requestBodyOut,
    InputStream responseBodyIn) {
  if (streamCancelled) {
    if (stream != null) {
      stream.closeLater(SpdyStream.RST_CANCEL);
      return true;
    } else {
      // If stream is null, it either means that writeRequestHeaders wasn't called
      // or that SpdyConnection#newStream threw an IOEXception. In both cases there's
      // nothing to do here and this stream can't be reused.
      return false;
    }
  }
  return true;
}
 
開發者ID:ikerexxe,項目名稱:RTRTA,代碼行數:16,代碼來源:SpdyTransport.java

示例5: receive

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
@Override public void receive(SpdyStream stream) throws IOException {
  RecordedRequest request = readRequest(stream);
  requestQueue.add(request);
  MockResponse response;
  try {
    response = dispatcher.dispatch(request);
  } catch (InterruptedException e) {
    throw new AssertionError(e);
  }
  writeResponse(stream, response);
  if (logger.isLoggable(Level.INFO)) {
    logger.info("Received request: " + request + " and responded: " + response
        + " protocol is " + protocol.name.utf8());
  }
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:16,代碼來源:MockWebServer.java

示例6: receive

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
@Override public void receive(final SpdyStream stream) throws IOException {
  RecordedRequest request = readRequest(stream);
  requestQueue.add(request);
  MockResponse response;
  try {
    response = dispatcher.dispatch(request);
  } catch (InterruptedException e) {
    throw new AssertionError(e);
  }
  writeResponse(stream, response);
  logger.info("Received request: " + request + " and responded: " + response);
}
 
開發者ID:c-ong,項目名稱:mirrored-okhttp,代碼行數:13,代碼來源:MockSpdyServer.java

示例7: readRequest

import com.squareup.okhttp.internal.spdy.SpdyStream; //導入依賴的package包/類
private RecordedRequest readRequest(SpdyStream stream) throws IOException {
  List<String> spdyHeaders = stream.getRequestHeaders();
  List<String> httpHeaders = new ArrayList<String>();
  String method = "<:method omitted>";
  String path = "<:path omitted>";
  String version = "<:version omitted>";
  for (Iterator<String> i = spdyHeaders.iterator(); i.hasNext(); ) {
    String name = i.next();
    String value = i.next();
    if (":method".equals(name)) {
      method = value;
    } else if (":path".equals(name)) {
      path = value;
    } else if (":version".equals(name)) {
      version = value;
    } else {
      httpHeaders.add(name + ": " + value);
    }
  }

  InputStream bodyIn = stream.getInputStream();
  ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
  byte[] buffer = new byte[8192];
  int count;
  while ((count = bodyIn.read(buffer)) != -1) {
    bodyOut.write(buffer, 0, count);
  }
  bodyIn.close();
  String requestLine = method + ' ' + path + ' ' + version;
  List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
  return new RecordedRequest(requestLine, httpHeaders, chunkSizes, bodyOut.size(),
      bodyOut.toByteArray(), sequenceNumber, socket);
}
 
開發者ID:c-ong,項目名稱:mirrored-okhttp,代碼行數:34,代碼來源:MockSpdyServer.java


注:本文中的com.squareup.okhttp.internal.spdy.SpdyStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。