本文整理了Java中okio.ByteString.read()
方法的一些代码示例,展示了ByteString.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.read()
方法的具体详情如下:
包路径:okio.ByteString
类名称:ByteString
方法名:read
[英]Reads count bytes from in and returns the result.
[中]从中读取计数字节并返回结果。
代码示例来源:origin: spotify/apollo
private Optional<ByteString> readPayload(HttpServletRequest req, int contentLength) throws IOException {
final InputStream input = new BufferedInputStream(req.getInputStream());
if (contentLength < 0) {
// contentLength = -1 may be returned when using Transfer-Encoding: chunked
// (RFC 7230, section 3.3.1: Transfer-Encoding) even though data is being transferred in a series of chunks.
// In that case try read this data before concluding that there is no payload.
final ByteString byteString = ByteString.of(ByteStreams.toByteArray(input));
return byteString.size() == 0 ? Optional.empty() : Optional.of(byteString);
} else {
return Optional.of(ByteString.read(input, contentLength));
}
}
代码示例来源:origin: square/okio
@Test public void read() throws Exception {
InputStream in = new ByteArrayInputStream("abc".getBytes(Charsets.UTF_8));
assertEquals(ByteString.decodeHex("6162"), ByteString.read(in, 2));
assertEquals(ByteString.decodeHex("63"), ByteString.read(in, 1));
assertEquals(ByteString.of(), ByteString.read(in, 0));
}
代码示例来源:origin: square/okio
@Test public void readAndToLowercase() throws Exception {
InputStream in = new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8));
assertEquals(ByteString.encodeUtf8("ab"), ByteString.read(in, 2).toAsciiLowercase());
assertEquals(ByteString.encodeUtf8("c"), ByteString.read(in, 1).toAsciiLowercase());
assertEquals(ByteString.EMPTY, ByteString.read(in, 0).toAsciiLowercase());
}
代码示例来源:origin: square/okio
@Test public void readAndToUppercase() throws Exception {
InputStream in = new ByteArrayInputStream("abc".getBytes(Charsets.UTF_8));
assertEquals(ByteString.encodeUtf8("AB"), ByteString.read(in, 2).toAsciiUppercase());
assertEquals(ByteString.encodeUtf8("C"), ByteString.read(in, 1).toAsciiUppercase());
assertEquals(ByteString.EMPTY, ByteString.read(in, 0).toAsciiUppercase());
}
代码示例来源:origin: huxq17/tractor
private void readObject(ObjectInputStream in) throws IOException {
int dataLength = in.readInt();
ByteString byteString = ByteString.read(in, dataLength);
try {
Field field = ByteString.class.getDeclaredField("data");
field.setAccessible(true);
field.set(this, byteString.data);
} catch (NoSuchFieldException e) {
throw new AssertionError();
} catch (IllegalAccessException e) {
throw new AssertionError();
}
}
内容来源于网络,如有侵权,请联系作者删除!