当前位置: 首页>>代码示例>>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;未经允许,请勿转载。