org.apache.jackrabbit.oak.commons.IOUtils.readBytes()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(159)

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

IOUtils.readBytes介绍

[英]Read a byte array. This will first read the length as 4 bytes, and then the actual bytes.
[中]读取字节数组。这将首先读取长度为4字节,然后读取实际字节。

代码示例

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Read a String. This will first read the length as 4 bytes, and then the
 * UTF-8 encoded string.
 *
 * @param in the data input stream
 * @return the string
 * @throws IOException if an IO exception occurred while reading
 */
public static String readString(InputStream in) throws IOException {
  return new String(readBytes(in), "UTF-8");
}

代码示例来源:origin: org.apache.jackrabbit/oak-commons

/**
 * Read a String. This will first read the length as 4 bytes, and then the
 * UTF-8 encoded string.
 *
 * @param in the data input stream
 * @return the string
 * @throws IOException if an IO exception occurred while reading
 */
public static String readString(InputStream in) throws IOException {
  return new String(readBytes(in), "UTF-8");
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * Read a String. This will first read the length as 4 bytes, and then the
 * UTF-8 encoded string.
 *
 * @param in the data input stream
 * @return the string
 * @throws IOException if an IO exception occurred while reading
 */
public static String readString(InputStream in) throws IOException {
  return new String(readBytes(in), "UTF-8");
}

代码示例来源:origin: org.apache.jackrabbit/oak-mk

@Override
public byte[] readBytesValue(String key) throws Exception {
  if (in == null) {
    throw new IllegalStateException("no InputStream provided");
  }
  return IOUtils.readBytes(in);
}

代码示例来源:origin: org.apache.jackrabbit/oak-mk

public BytesEntry next() {
  if (count-- > 0) {
    try {
      String key = IOUtils.readString(in);
      byte[] value = IOUtils.readBytes(in);
      return new BytesEntry(key, value);
    } catch (IOException e) {
      throw new RuntimeException("deserialization failed", e);
    }
  }
  throw new NoSuchElementException();
}

代码示例来源:origin: apache/jackrabbit-oak

public void testBytesReadWrite() throws IOException {
  final Random r = new Random();
  int iterations = 1000;
  while (iterations-- > 0) {
    int n = Math.abs(r.nextInt()) % 0x40000;
    byte[] buf = new byte[n];
    r.nextBytes(buf);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.writeBytes(out, buf);
    byte[] buf1 = IOUtils.readBytes(new ByteArrayInputStream(out.toByteArray()));
    assertEquals(buf, buf1);
  }
}

相关文章