本文整理汇总了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();
}
}
示例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();
}
}
}
示例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");
}