okio.BufferedSource.readFully()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中okio.BufferedSource.readFully()方法的一些代码示例,展示了BufferedSource.readFully()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedSource.readFully()方法的具体详情如下:
包路径:okio.BufferedSource
类名称:BufferedSource
方法名:readFully

BufferedSource.readFully介绍

[英]Removes exactly byteCount bytes from this and appends them to sink. Throws an java.io.EOFException if the requested number of bytes cannot be read.
[中]从中完全删除字节数字节,并将它们附加到接收器。抛出一个java。木卫一。如果无法读取请求的字节数,则为EOFEException。

代码示例

代码示例来源:origin: square/okhttp

private void readTheList() throws IOException {
 byte[] publicSuffixListBytes;
 byte[] publicSuffixExceptionListBytes;
 InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
 if (resource == null) return;
 try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) {
  int totalBytes = bufferedSource.readInt();
  publicSuffixListBytes = new byte[totalBytes];
  bufferedSource.readFully(publicSuffixListBytes);
  int totalExceptionBytes = bufferedSource.readInt();
  publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
  bufferedSource.readFully(publicSuffixExceptionListBytes);
 }
 synchronized (this) {
  this.publicSuffixListBytes = publicSuffixListBytes;
  this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
 }
 readCompleteLatch.countDown();
}

代码示例来源:origin: seven332/EhViewer

public EhTagDatabase(String name, BufferedSource source) throws IOException {
 this.name = name;
 int totalBytes = source.readInt();
 tags = new byte[totalBytes];
 source.readFully(tags);
}

代码示例来源:origin: seven332/EhViewer

@Nullable
private static byte[] getFileContent(File file, int length) {
 try (BufferedSource source = Okio.buffer(Okio.source(file))) {
  byte[] content = new byte[length];
  source.readFully(content);
  return content;
 } catch (IOException e) {
  return null;
 }
}

代码示例来源:origin: square/okhttp

private void parseData(Buffer data, long end) throws IOException {
 data.writeByte('\n');
 end -= skipNameAndDivider(4L);
 source.readFully(data, end);
 skipCrAndOrLf();
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

private void readTheList() throws IOException {
 byte[] publicSuffixListBytes;
 byte[] publicSuffixExceptionListBytes;
 InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
 if (resource == null) return;
 try (BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)))) {
  int totalBytes = bufferedSource.readInt();
  publicSuffixListBytes = new byte[totalBytes];
  bufferedSource.readFully(publicSuffixListBytes);
  int totalExceptionBytes = bufferedSource.readInt();
  publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
  bufferedSource.readFully(publicSuffixExceptionListBytes);
 }
 synchronized (this) {
  this.publicSuffixListBytes = publicSuffixListBytes;
  this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
 }
 readCompleteLatch.countDown();
}

代码示例来源:origin: square/okhttp

/**
  * Reads a message body into across one or more frames. Control frames that occur between
  * fragments will be processed. If the message payload is masked this will unmask as it's being
  * processed.
  */
 private void readMessage() throws IOException {
  while (true) {
   if (closed) throw new IOException("closed");

   if (frameLength > 0) {
    source.readFully(messageFrameBuffer, frameLength);

    if (!isClient) {
     messageFrameBuffer.readAndWriteUnsafe(maskCursor);
     maskCursor.seek(messageFrameBuffer.size() - frameLength);
     toggleMask(maskCursor, maskKey);
     maskCursor.close();
    }
   }

   if (isFinalFrame) break; // We are exhausted and have no continuations.

   readUntilNonControlFrame();
   if (opcode != OPCODE_CONTINUATION) {
    throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode));
   }
  }
 }
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
  * Reads a message body into across one or more frames. Control frames that occur between
  * fragments will be processed. If the message payload is masked this will unmask as it's being
  * processed.
  */
 private void readMessage() throws IOException {
  while (true) {
   if (closed) throw new IOException("closed");

   if (frameLength > 0) {
    source.readFully(messageFrameBuffer, frameLength);

    if (!isClient) {
     messageFrameBuffer.readAndWriteUnsafe(maskCursor);
     maskCursor.seek(messageFrameBuffer.size() - frameLength);
     toggleMask(maskCursor, maskKey);
     maskCursor.close();
    }
   }

   if (isFinalFrame) break; // We are exhausted and have no continuations.

   readUntilNonControlFrame();
   if (opcode != OPCODE_CONTINUATION) {
    throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode));
   }
  }
 }
}

代码示例来源:origin: square/okio

@Test public void readFullyTooShortThrows() throws IOException {
 sink.writeUtf8("Hi");
 sink.emit();
 Buffer sink = new Buffer();
 try {
  source.readFully(sink, 5);
  fail();
 } catch (EOFException ignored) {
 }
 // Verify we read all that we could from the source.
 assertEquals("Hi", sink.readUtf8());
}

代码示例来源:origin: square/okhttp

source.readFully(maskKey);

代码示例来源:origin: square/okio

@Test public void readFullyByteArrayTooShortThrows() throws IOException {
 sink.writeUtf8("Hello");
 sink.emit();
 byte[] array = new byte[6];
 try {
  source.readFully(array);
  fail();
 } catch (EOFException ignored) {
 }
 // Verify we read all that we could from the source.
 assertByteArraysEquals(new byte[] { 'H', 'e', 'l', 'l', 'o', 0 }, array);
}

代码示例来源:origin: square/okhttp

private void readControlFrame() throws IOException {
 if (frameLength > 0) {
  source.readFully(controlFrameBuffer, frameLength);

代码示例来源:origin: square/okio

@Test public void readFully() throws Exception {
 sink.writeUtf8(repeat('a', 10000));
 sink.emit();
 Buffer sink = new Buffer();
 source.readFully(sink, 9999);
 assertEquals(repeat('a', 9999), sink.readUtf8());
 assertEquals("a", source.readUtf8());
}

代码示例来源:origin: square/okio

@Test public void readFullyByteArray() throws IOException {
 Buffer data = new Buffer();
 data.writeUtf8("Hello").writeUtf8(repeat('e', SEGMENT_SIZE));
 byte[] expected = data.clone().readByteArray();
 sink.write(data, data.size());
 sink.emit();
 byte[] sink = new byte[SEGMENT_SIZE + 5];
 source.readFully(sink);
 assertByteArraysEquals(expected, sink);
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

source.readFully(maskKey);

代码示例来源:origin: com.squareup.okhttp3/okhttp

private void readControlFrame() throws IOException {
 if (frameLength > 0) {
  source.readFully(controlFrameBuffer, frameLength);

代码示例来源:origin: com.github.ljun20160606/okhttp

private void readTheList() throws IOException {
 byte[] publicSuffixListBytes;
 byte[] publicSuffixExceptionListBytes;
 InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
 if (resource == null) return;
 BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)));
 try {
  int totalBytes = bufferedSource.readInt();
  publicSuffixListBytes = new byte[totalBytes];
  bufferedSource.readFully(publicSuffixListBytes);
  int totalExceptionBytes = bufferedSource.readInt();
  publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
  bufferedSource.readFully(publicSuffixExceptionListBytes);
 } finally {
  closeQuietly(bufferedSource);
 }
 synchronized (this) {
  this.publicSuffixListBytes = publicSuffixListBytes;
  this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
 }
 readCompleteLatch.countDown();
}

代码示例来源:origin: apache/servicemix-bundles

private void readTheList() throws IOException {
 byte[] publicSuffixListBytes;
 byte[] publicSuffixExceptionListBytes;
 InputStream resource = PublicSuffixDatabase.class.getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
 if (resource == null) return;
 BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(resource)));
 try {
  int totalBytes = bufferedSource.readInt();
  publicSuffixListBytes = new byte[totalBytes];
  bufferedSource.readFully(publicSuffixListBytes);
  int totalExceptionBytes = bufferedSource.readInt();
  publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
  bufferedSource.readFully(publicSuffixExceptionListBytes);
 } finally {
  closeQuietly(bufferedSource);
 }
 synchronized (this) {
  this.publicSuffixListBytes = publicSuffixListBytes;
  this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
 }
 readCompleteLatch.countDown();
}

代码示例来源:origin: com.squareup.okhttp3/okhttp-sse

private void parseData(Buffer data, long end) throws IOException {
 data.writeByte('\n');
 end -= skipNameAndDivider(4L);
 source.readFully(data, end);
 skipCrAndOrLf();
}

代码示例来源:origin: apache/servicemix-bundles

/**
  * Reads a message body into across one or more frames. Control frames that occur between
  * fragments will be processed. If the message payload is masked this will unmask as it's being
  * processed.
  */
 private void readMessage() throws IOException {
  while (true) {
   if (closed) throw new IOException("closed");

   if (frameLength > 0) {
    source.readFully(messageFrameBuffer, frameLength);

    if (!isClient) {
     messageFrameBuffer.readAndWriteUnsafe(maskCursor);
     maskCursor.seek(messageFrameBuffer.size() - frameLength);
     toggleMask(maskCursor, maskKey);
     maskCursor.close();
    }
   }

   if (isFinalFrame) break; // We are exhausted and have no continuations.

   readUntilNonControlFrame();
   if (opcode != OPCODE_CONTINUATION) {
    throw new ProtocolException("Expected continuation opcode. Got: " + toHexString(opcode));
   }
  }
 }
}

代码示例来源:origin: com.squareup.okhttp/okhttp-ws

source.readFully(maskKey);

相关文章

微信公众号

最新文章

更多