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

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

本文整理了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

  1. /**
  2. * <p>
  3. * Convenience method to return the entry's content as a String if isUnixSymlink()
  4. * returns true for it, otherwise returns null.
  5. * </p>
  6. *
  7. * <p>This method assumes the symbolic link's file name uses the
  8. * same encoding that as been specified for this ZipFile.</p>
  9. *
  10. * @param entry ZipArchiveEntry object that represents the symbolic link
  11. * @return entry's content as a String
  12. * @throws IOException problem with content's input stream
  13. * @since 1.5
  14. */
  15. public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException {
  16. if (entry != null && entry.isUnixSymlink()) {
  17. try (InputStream in = getInputStream(entry)) {
  18. return zipEncoding.decode(IOUtils.toByteArray(in));
  19. }
  20. }
  21. return null;
  22. }

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

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

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

  1. @Test
  2. public void testAssemble() throws Exception
  3. {
  4. InputStream in = AssemblerTest.class.getResourceAsStream(script);
  5. Assert.assertNotNull(in);
  6. Instructions instructions = new Instructions();
  7. instructions.init();
  8. Assembler assembler = new Assembler(instructions);
  9. ScriptDefinition script = assembler.assemble(in);
  10. // compare with disassembler
  11. Disassembler disassembler = new Disassembler();
  12. String out = disassembler.disassemble(script);
  13. in = AssemblerTest.class.getResourceAsStream(this.script);
  14. Assert.assertNotNull(in);
  15. String original = new String(IOUtils.toByteArray(in)).replaceAll("\r\n", "\n");
  16. logger.info(original);
  17. logger.info("-----------------------");
  18. logger.info(out);
  19. Assert.assertEquals(original, out);
  20. }

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

  1. @Override
  2. public void decode(InputStream inputStream) throws IOException {
  3. byte[] b = IOUtils.toByteArray(inputStream);
  4. decode(b);
  5. }
  6. }

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

  1. @Override
  2. public byte[] next() {
  3. try {
  4. ZipArchiveEntry entry = this.iter.nextElement();
  5. try (InputStream in = this.zf.getInputStream(entry);) {
  6. byte[] bytes = IOUtils.toByteArray(in);
  7. return bytes;
  8. }
  9. } catch (IOException e) {
  10. throw new RuntimeException(e);
  11. }
  12. }

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

  1. /***
  2. * Read and deserialized Spec from a file.
  3. * @param path File containing serialized Spec.
  4. * @return Spec
  5. * @throws IOException
  6. */
  7. protected Spec readSpecFromFile(Path path) throws IOException {
  8. Spec spec = null;
  9. try (FSDataInputStream fis = fs.open(path);) {
  10. spec = this.specSerDe.deserialize(IOUtils.toByteArray(fis));
  11. }
  12. return spec;
  13. }

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

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

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

  1. @Override
  2. public void decode(InputStream inputStream) throws IOException {
  3. decode(IOUtils.toByteArray(inputStream));
  4. }
  5. }

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

  1. @Override
  2. public void decode(InputStream inputStream) throws IOException {
  3. decode(IOUtils.toByteArray(inputStream));
  4. }
  5. }

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

  1. @Override
  2. public void decode(InputStream inputStream) throws IOException {
  3. byte[] b = IOUtils.toByteArray(inputStream);
  4. decode(b);
  5. }
  6. }

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

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

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

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

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

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

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

  1. /**
  2. * {@inheritDoc}
  3. *
  4. * @throws UncheckedIOException if an I/O error occurs
  5. */
  6. @Nonnull
  7. @Override
  8. protected final String getScript() {
  9. try (InputStream is = getInputStream()) {
  10. return new String(IOUtils.toByteArray(is), getEncoding());
  11. }
  12. catch (IOException ex) {
  13. throw new UncheckedIOException(String.format("Could not open a stream for CQL Script (%s)", toString()),
  14. ex);
  15. }
  16. }

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

  1. private void sendStatic(ChannelHandlerContext context,
  2. String fileUri,
  3. String contentType) throws IOException {
  4. File staticFile = fileManager.getStaticFile(fileUri);
  5. if (staticFile == null) {
  6. throw new RuntimeException("Cannot find static files. File uri: " + fileUri);
  7. }
  8. try (InputStream inputStream = new FileInputStream(staticFile)) {
  9. sendBytes(context, contentType, IOUtils.toByteArray(inputStream));
  10. }
  11. }

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

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

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

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

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

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

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

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

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

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

相关文章