org.apache.commons.compress.utils.IOUtils.toByteArray()方法的使用及代码示例

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

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

IOUtils.toByteArray介绍

[英]Gets the contents of an InputStream as a byte[].

This method buffers the input internally, so there is no need to use a BufferedInputStream.
[中]将InputStream的内容获取为byte[]
此方法在内部缓冲输入,因此无需使用BufferedInputStream

代码示例

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

/**
 * <p>
 * Convenience method to return the entry's content as a String if isUnixSymlink()
 * returns true for it, otherwise returns null.
 * </p>
 *
 * <p>This method assumes the symbolic link's file name uses the
 * same encoding that as been specified for this ZipFile.</p>
 *
 * @param entry ZipArchiveEntry object that represents the symbolic link
 * @return entry's content as a String
 * @throws IOException problem with content's input stream
 * @since 1.5
 */
public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException {
  if (entry != null && entry.isUnixSymlink()) {
    try (InputStream in = getInputStream(entry)) {
      return zipEncoding.decode(IOUtils.toByteArray(in));
    }
  }
  return null;
}

代码示例来源:origin: cSploit/android

notifier = new Notifier(task, IOUtils.toByteArray(stream), isError);
 stream.close();
} catch (IOException e) {

代码示例来源:origin: runelite/runelite

@Test
public void testAssemble() throws Exception
{
  InputStream in = AssemblerTest.class.getResourceAsStream(script);
  Assert.assertNotNull(in);
  Instructions instructions = new Instructions();
  instructions.init();
  Assembler assembler = new Assembler(instructions);
  ScriptDefinition script = assembler.assemble(in);
  // compare with disassembler
  Disassembler disassembler = new Disassembler();
  String out = disassembler.disassemble(script);
  in = AssemblerTest.class.getResourceAsStream(this.script);
  Assert.assertNotNull(in);
  String original = new String(IOUtils.toByteArray(in)).replaceAll("\r\n", "\n");
  logger.info(original);
  logger.info("-----------------------");
  logger.info(out);
  Assert.assertEquals(original, out);
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
  public void decode(InputStream inputStream) throws IOException {
    byte[] b = IOUtils.toByteArray(inputStream);
    decode(b);
  }
}

代码示例来源:origin: edu.jhu.hlt/acute

@Override
public byte[] next() {
 try {
  ZipArchiveEntry entry = this.iter.nextElement();
  try (InputStream in = this.zf.getInputStream(entry);) {
   byte[] bytes = IOUtils.toByteArray(in);
   return bytes;
  }
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: com.linkedin.gobblin/gobblin-runtime

/***
 * Read and deserialized Spec from a file.
 * @param path File containing serialized Spec.
 * @return Spec
 * @throws IOException
 */
protected Spec readSpecFromFile(Path path) throws IOException {
 Spec spec = null;
 try (FSDataInputStream fis = fs.open(path);) {
  spec = this.specSerDe.deserialize(IOUtils.toByteArray(fis));
 }
 return spec;
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
public void decode(InputStream inputStream) throws IOException {
  byte[] b = IOUtils.toByteArray(inputStream);
  decode(b);
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
  public void decode(InputStream inputStream) throws IOException {
    decode(IOUtils.toByteArray(inputStream));
  }
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
  public void decode(InputStream inputStream) throws IOException {
    decode(IOUtils.toByteArray(inputStream));
  }
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
  public void decode(InputStream inputStream) throws IOException {
    byte[] b = IOUtils.toByteArray(inputStream);
    decode(b);
  }
}

代码示例来源:origin: org.deeplearning4j/arbiter-ui

@Override
public void decode(InputStream inputStream) throws IOException {
  decode(IOUtils.toByteArray(inputStream));
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-ui-model

@Override
public void decode(InputStream inputStream) throws IOException {
  decode(IOUtils.toByteArray(inputStream));
}

代码示例来源:origin: viniciusccarvalho/schema-evolution-samples

@Override
public <T> T decode(InputStream inputStream, Class<T> type) throws IOException {
  return decode(IOUtils.toByteArray(inputStream),type);
}

代码示例来源:origin: com.github.nosan/embedded-cassandra

/**
 * {@inheritDoc}
 *
 * @throws UncheckedIOException if an I/O error occurs
 */
@Nonnull
@Override
protected final String getScript() {
  try (InputStream is = getInputStream()) {
    return new String(IOUtils.toByteArray(is), getEncoding());
  }
  catch (IOException ex) {
    throw new UncheckedIOException(String.format("Could not open a stream for CQL Script (%s)", toString()),
        ex);
  }
}

代码示例来源:origin: kornilova-l/FlameViewer

private void sendStatic(ChannelHandlerContext context,
            String fileUri,
            String contentType) throws IOException {
  File staticFile = fileManager.getStaticFile(fileUri);
  if (staticFile == null) {
    throw new RuntimeException("Cannot find static files. File uri: " + fileUri);
  }
  try (InputStream inputStream = new FileInputStream(staticFile)) {
    sendBytes(context, contentType, IOUtils.toByteArray(inputStream));
  }
}

代码示例来源:origin: org.nd4j/canova-nd4j-codec

@Override
public Collection<Collection<Writable>> sequenceRecord(URI uri, DataInputStream dataInputStream) throws IOException {
  //Reading video from DataInputStream: Need data from this stream in a SeekableByteChannel
  //Approach used here: load entire video into memory -> ByteBufferSeekableByteChanel
  byte[] data = IOUtils.toByteArray(dataInputStream);
  ByteBuffer bb = ByteBuffer.wrap(data);
  SeekableByteChannel sbc = new FixedByteBufferSeekableByteChannel(bb);
  return loadData(sbc);
}

代码示例来源:origin: carlossg/jenkins-kubernetes-plugin

public static String loadPipelineScript(Class<?> clazz, String name) {
  try {
    return new String(IOUtils.toByteArray(clazz.getResourceAsStream(name)));
  } catch (Throwable t) {
    throw new RuntimeException("Could not read resource:[" + name + "].");
  }
}

代码示例来源:origin: carlossg/jenkins-kubernetes-plugin

protected String loadPipelineScript(String name) {
  try {
    return new String(IOUtils.toByteArray(getClass().getResourceAsStream(name)));
  } catch (Throwable t) {
    throw new RuntimeException("Could not read resource:[" + name + "].");
  }
}

代码示例来源:origin: carlossg/jenkins-kubernetes-plugin

@Test
public void testOverridesFromYaml() throws Exception {
  PodTemplate template = new PodTemplate();
  template.setYaml(new String(IOUtils.toByteArray(getClass().getResourceAsStream("pod-overrides.yaml"))));
  setupStubs();
  Pod pod = new PodTemplateBuilder(template).withSlave(slave).build();
  Map<String, Container> containers = pod.getSpec().getContainers().stream()
      .collect(Collectors.toMap(Container::getName, Function.identity()));
  assertEquals(1, containers.size());
  validateJnlpContainer(containers.get("jnlp"), slave);
}

代码示例来源:origin: carlossg/jenkins-kubernetes-plugin

@Test
public void testBuildWithoutSlave() throws Exception {
  slave = null;
  PodTemplate template = new PodTemplate();
  template.setYaml(new String(IOUtils.toByteArray(getClass().getResourceAsStream("pod-busybox.yaml"))));
  Pod pod = new PodTemplateBuilder(template).build();
  validatePod(pod);
}

相关文章