org.apache.commons.compress.utils.IOUtils类的使用及代码示例

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

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

IOUtils介绍

[英]Utility functions
[中]效用函数

代码示例

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

  1. public static byte[] compress(byte[] bytes) throws IOException
  2. {
  3. InputStream is = new ByteArrayInputStream(bytes);
  4. ByteArrayOutputStream bout = new ByteArrayOutputStream();
  5. try (OutputStream os = new GZIPOutputStream(bout))
  6. {
  7. IOUtils.copy(is, os);
  8. }
  9. return bout.toByteArray();
  10. }

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

  1. private void movePcapFileFromCacheToStorage() {
  2. File inputFile = new File(mPcapFileName);
  3. InputStream in = null;
  4. OutputStream out = null;
  5. try {
  6. in = new FileInputStream(inputFile);
  7. out = new FileOutputStream(new File(System.getStoragePath(),new File(mPcapFileName).getName()));
  8. IOUtils.copy(in, out);
  9. } catch (IOException e) {
  10. System.errorLogging(e);
  11. } finally {
  12. IOUtils.closeQuietly(in);
  13. IOUtils.closeQuietly(out);
  14. inputFile.delete();
  15. }
  16. }

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

  1. int len = 0;
  2. int read = 0;
  3. while((ch = i.read()) != -1) {
  4. read++;
  5. if (ch == '\n') { // blank line in header
  6. } else if (ch == ' '){ // End of length string
  7. final ByteArrayOutputStream coll = new ByteArrayOutputStream();
  8. while((ch = i.read()) != -1) {
  9. read++;
  10. if (ch == '='){ // end of keyword
  11. final String keyword = coll.toString(CharsetNames.UTF_8);
  12. } else {
  13. final byte[] rest = new byte[restLen];
  14. final int got = IOUtils.readFully(i, rest);
  15. if (got != restLen) {
  16. throw new IOException("Failed to read "
  17. coll.write((byte) ch);

代码示例来源:origin: apache/hive

  1. is = new GzipCompressorInputStream(new FileInputStream(inputFile));
  2. } else {
  3. is = new FileInputStream(inputFile);
  4. (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
  5. TarArchiveEntry entry = null;
  6. while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
  7. File flatOutputFile = new File(outputDir, outputFile.getName());
  8. LOG.debug(String.format("Creating flat output file %s.", flatOutputFile.getAbsolutePath()));
  9. outputFileStream = new FileOutputStream(flatOutputFile);
  10. } else if (!outputFile.getParentFile().exists()) {
  11. LOG.debug(String.format("Attempting to create output directory %s.",
  12. outputFileStream = new FileOutputStream(outputFile);
  13. } else {
  14. outputFileStream = new FileOutputStream(outputFile);
  15. IOUtils.copy(debInputStream, outputFileStream);
  16. outputFileStream.close();

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

  1. counter = new CountingInputStream(new FileInputStream(inFile));
  2. is = openArchiveStream(counter);
  3. isTar = mCurrentTask.archiver.equals(archiveAlgorithm.tar);
  4. byte[] writeMe = null;
  5. outputStream = new FileOutputStream(f);
  6. writeMe = buffer = new byte[4];
  7. IOUtils.readFully(is, buffer);
  8. isScript = true;
  9. ByteArrayOutputStream firstLine = new ByteArrayOutputStream();
  10. int newline = -1;
  11. firstLine.write(buffer, 0, count);
  12. outputStream.write(writeMe);
  13. IOUtils.copy(is, outputStream);
  14. outputStream.close();
  15. outputStream = null;

代码示例来源:origin: org.apache.logging.log4j/log4j-core

  1. assertNotNull(files);
  2. for (final File file : files) {
  3. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. try (FileInputStream fis = new FileInputStream(file)) {
  5. try {
  6. IOUtils.copy(fis, baos);
  7. } catch (final Exception ex) {
  8. ex.printStackTrace();
  9. final String text = new String(baos.toByteArray(), Charset.defaultCharset());
  10. final String[] lines = text.split("[\\r\\n]+");
  11. for (final String line : lines) {

代码示例来源:origin: jeremylong/DependencyCheck

  1. /**
  2. * Extracts the file contained in a gzip archive. The extracted file is
  3. * placed in the exact same path as the file specified.
  4. *
  5. * @param file the archive file
  6. * @throws FileNotFoundException thrown if the file does not exist
  7. * @throws IOException thrown if there is an error extracting the file.
  8. */
  9. public static void extractGzip(File file) throws FileNotFoundException, IOException {
  10. final String originalPath = file.getPath();
  11. final File gzip = new File(originalPath + ".gz");
  12. if (gzip.isFile() && !gzip.delete()) {
  13. LOGGER.debug("Failed to delete initial temporary file when extracting 'gz' {}", gzip.toString());
  14. gzip.deleteOnExit();
  15. }
  16. if (!file.renameTo(gzip)) {
  17. throw new IOException("Unable to rename '" + file.getPath() + "'");
  18. }
  19. final File newFile = new File(originalPath);
  20. try (FileInputStream fis = new FileInputStream(gzip);
  21. GZIPInputStream cin = new GZIPInputStream(fis);
  22. FileOutputStream out = new FileOutputStream(newFile)) {
  23. IOUtils.copy(cin, out);
  24. } finally {
  25. if (gzip.isFile() && !org.apache.commons.io.FileUtils.deleteQuietly(gzip)) {
  26. LOGGER.debug("Failed to delete temporary file when extracting 'gz' {}", gzip.toString());
  27. gzip.deleteOnExit();
  28. }
  29. }
  30. }

代码示例来源:origin: org.apache.logging.log4j/log4j-core

  1. int gzippedFiles = 0;
  2. for (final File file : files) {
  3. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. InputStream in = null;
  5. final FileExtension ext = FileExtension.lookupForFile(file.getName());
  6. try {
  7. try (FileInputStream fis = new FileInputStream(file)) {
  8. if (ext != null) {
  9. gzippedFiles++;
  10. try {
  11. in = new CompressorStreamFactory().createCompressorInputStream(ext.name().toLowerCase(),
  12. fis);
  13. } catch (final CompressorException ce) {
  14. in = new FileInputStream(file);
  15. IOUtils.copy(in, baos);
  16. } catch (final Exception ex) {
  17. ex.printStackTrace();
  18. Closer.close(in);
  19. final String text = new String(baos.toByteArray(), Charset.defaultCharset());
  20. final String[] lines = text.split("[\\r\\n]+");
  21. for (final String line : lines) {

代码示例来源:origin: apache/hive

  1. public static void zip(String parentDir, String[] inputFiles, String outputFile)
  2. throws IOException {
  3. ZipOutputStream output = null;
  4. try {
  5. output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
  6. for (int i = 0; i < inputFiles.length; i++) {
  7. File f = new File(parentDir, inputFiles[i]);
  8. FileInputStream input = new FileInputStream(f);
  9. output.putNextEntry(new ZipEntry(inputFiles[i]));
  10. try {
  11. IOUtils.copy(input, output);
  12. } finally {
  13. input.close();
  14. }
  15. }
  16. } finally {
  17. org.apache.hadoop.io.IOUtils.closeStream(output);
  18. }
  19. }

代码示例来源:origin: cn.easyproject/easybackup

  1. in = new TarArchiveInputStream(new BufferedInputStream(new FileInputStream(tarFile)));
  2. } else {
  3. in = new TarArchiveInputStream(new BufferedInputStream(new FileInputStream(tarFile)), encoding);
  4. OutputStream out = new FileOutputStream(outFile);
  5. IOUtils.copy(in, out); // 3、写出文件
  6. out.close();

代码示例来源:origin: cn.easyproject/easybackup

  1. zos = (ZipArchiveOutputStream) new ArchiveStreamFactory()
  2. .createArchiveOutputStream(ArchiveStreamFactory.ZIP, new BufferedOutputStream(new FileOutputStream(zipFile)));
  3. ZipArchiveEntry zae = new ZipArchiveEntry(srcFile.getName());// 1创建
  4. bis=new BufferedInputStream(new FileInputStream(srcFile));
  5. IOUtils.copy(bis, zos); // 3写入

代码示例来源:origin: googleapis/google-cloud-java

  1. FileOutputStream os = new FileOutputStream(tmpArchive)) {
  2. while ((bytesRead = is.read(dataBuffer, 0, 1024)) != -1) {
  3. digest.update(dataBuffer, 0, bytesRead);
  4. os.write(dataBuffer, 0, bytesRead);
  5. new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tmpArchive)))) {
  6. try (OutputStream outputFileStream = new FileOutputStream(dest)) {
  7. IOUtils.copy(stream, outputFileStream);

代码示例来源:origin: t7mp/maven-t7-plugin

  1. continue;
  2. OutputStream o = new FileOutputStream(outfile);
  3. try {
  4. IOUtils.copy(in, o);
  5. } finally {
  6. o.close();
  7. warInputStream.close();
  8. } catch (FileNotFoundException e) {
  9. throw new TomcatSetupException(e.getMessage(), e);

代码示例来源:origin: org.apache.openejb/apache-tomee-deb-package

  1. private File compress(File file) throws IOException, CompressorException {
  2. final File output = new File(file.getParent(), file.getName() + ".gz");
  3. output.delete();
  4. final OutputStream out = new FileOutputStream(output);
  5. final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out);
  6. final FileInputStream is = new FileInputStream(file);
  7. IOUtils.copy(is, cos);
  8. is.close();
  9. cos.close();
  10. out.close();
  11. return output;
  12. }

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

  1. /**
  2. * Gets the contents of an <code>InputStream</code> as a <code>byte[]</code>.
  3. * <p>
  4. * This method buffers the input internally, so there is no need to use a
  5. * <code>BufferedInputStream</code>.
  6. *
  7. * @param input the <code>InputStream</code> to read from
  8. * @return the requested byte array
  9. * @throws NullPointerException if the input is null
  10. * @throws IOException if an I/O error occurs
  11. * @since 1.5
  12. */
  13. public static byte[] toByteArray(final InputStream input) throws IOException {
  14. final ByteArrayOutputStream output = new ByteArrayOutputStream();
  15. copy(input, output);
  16. return output.toByteArray();
  17. }

代码示例来源:origin: apache/avro

  1. @Override
  2. public ByteBuffer decompress(ByteBuffer compressedData) throws IOException {
  3. ByteArrayOutputStream baos = getOutputBuffer(compressedData.remaining());
  4. InputStream bytesIn = new ByteArrayInputStream(
  5. compressedData.array(),
  6. computeOffset(compressedData),
  7. compressedData.remaining());
  8. try (InputStream ios = new ZstdCompressorInputStream(bytesIn)) {
  9. IOUtils.copy(ios, baos);
  10. }
  11. return ByteBuffer.wrap(baos.toByteArray());
  12. }

代码示例来源:origin: apache/storm

  1. private File loadExample(File file, String example) {
  2. try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(example)) {
  3. file = File.createTempFile("pmml-example", ".tmp");
  4. IOUtils.copy(stream, new FileOutputStream(file));
  5. } catch (IOException e) {
  6. throw new RuntimeException("Error loading example " + example, e);
  7. }
  8. return file;
  9. }

代码示例来源:origin: org.apache.openejb/apache-tomee-deb-package

  1. private File uncompress(File gz) throws IOException, CompressorException {
  2. final File output = new File(gz.getParent(), FilenameUtils.getBaseName(gz.getName()));
  3. output.delete();
  4. final InputStream is = new FileInputStream(gz);
  5. final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is);
  6. IOUtils.copy(in, new FileOutputStream(output));
  7. in.close();
  8. return output;
  9. }

代码示例来源:origin: gradle.plugin.net.karlmartens.dotnet/dotnet-plugin

  1. targetFile.createNewFile();
  2. try (ArchiveOutputStream out = new ArchiveStreamFactory().createArchiveOutputStream(getExtension().getArchiveAs(), new FileOutputStream(targetFile, false))) {
  3. for (String includedFile : scanner.getIncludedFiles()) {
  4. LOGGER.debug("Adding file {}", includedFile);
  5. File f = source.resolve(includedFile).toFile();
  6. out.putArchiveEntry(buildArchiveEntry(f));
  7. IOUtils.copy(new FileInputStream(file), out);
  8. out.closeArchiveEntry();
  9. final String compressedTarget = targetFile.getAbsolutePath() + "." + getExtension().getCompressAs();
  10. LOGGER.quiet("Compress {}.", compressedTarget);
  11. try (FileOutputStream out = new FileOutputStream(compressedTarget, false)) {
  12. CompressorStreamFactory factory = new CompressorStreamFactory();
  13. try (CompressorOutputStream compressorStream = factory.createCompressorOutputStream(getExtension().getCompressAs(), out)) {
  14. IOUtils.copy(new FileInputStream(targetFile), compressorStream);

代码示例来源:origin: org.apache.openejb/apache-tomee-deb-package

  1. private void ar(File file, ArchiveOutputStream os) throws IOException {
  2. os.putArchiveEntry(new ArArchiveEntry(file.getName(), file.length()));
  3. final InputStream input = new FileInputStream(file);
  4. try {
  5. IOUtils.copy(input, os);
  6. } finally {
  7. input.close();
  8. }
  9. os.closeArchiveEntry();
  10. }

相关文章