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


Java Util.readFully方法代碼示例

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


在下文中一共展示了Util.readFully方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bytes

import com.squareup.okhttp.internal.Util; //導入方法依賴的package包/類
public final byte[] bytes() throws IOException {
  long contentLength = contentLength();
  if (contentLength > Integer.MAX_VALUE) {
    throw new IOException("Cannot buffer entire body for content length: " + contentLength);
  }

  if (contentLength != -1) {
    byte[] content = new byte[(int) contentLength];
    InputStream in = byteStream();
    Util.readFully(in, content);
    if (in.read() != -1) throw new IOException("Content-Length and stream length disagree");
    return content;

  } else {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Util.copy(byteStream(), out);
    return out.toByteArray();
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:20,代碼來源:Response.java

示例2: receive

import com.squareup.okhttp.internal.Util; //導入方法依賴的package包/類
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();
    }
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:60,代碼來源:SpdyStream.java

示例3: readString

import com.squareup.okhttp.internal.Util; //導入方法依賴的package包/類
private String readString() throws DataFormatException, IOException {
  int length = nameValueBlockIn.readInt();
  byte[] bytes = new byte[length];
  Util.readFully(nameValueBlockIn, bytes);
  return new String(bytes, 0, length, "UTF-8");
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:7,代碼來源:NameValueBlockReader.java


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