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

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

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

public static byte[] compress(byte[] bytes) throws IOException
{
  InputStream is = new ByteArrayInputStream(bytes);
  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  try (OutputStream os = new GZIPOutputStream(bout))
  {
    IOUtils.copy(is, os);
  }
  
  return bout.toByteArray();
}

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

private void movePcapFileFromCacheToStorage() {
 File inputFile = new File(mPcapFileName);
 InputStream in = null;
 OutputStream out = null;
 try {
  in = new FileInputStream(inputFile);
  out = new FileOutputStream(new File(System.getStoragePath(),new File(mPcapFileName).getName()));
  IOUtils.copy(in, out);
 } catch (IOException e) {
  System.errorLogging(e);
 } finally {
  IOUtils.closeQuietly(in);
  IOUtils.closeQuietly(out);
  inputFile.delete();
 }
}

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

int len = 0;
int read = 0;
while((ch = i.read()) != -1) {
  read++;
  if (ch == '\n') { // blank line in header
  } else if (ch == ' '){ // End of length string
    final ByteArrayOutputStream coll = new ByteArrayOutputStream();
    while((ch = i.read()) != -1) {
      read++;
      if (ch == '='){ // end of keyword
        final String keyword = coll.toString(CharsetNames.UTF_8);
        } else {
          final byte[] rest = new byte[restLen];
          final int got = IOUtils.readFully(i, rest);
          if (got != restLen) {
            throw new IOException("Failed to read "
      coll.write((byte) ch);

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

is = new GzipCompressorInputStream(new FileInputStream(inputFile));
} else {
 is = new FileInputStream(inputFile);
  (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
   File flatOutputFile = new File(outputDir, outputFile.getName());
   LOG.debug(String.format("Creating flat output file %s.", flatOutputFile.getAbsolutePath()));
   outputFileStream = new FileOutputStream(flatOutputFile);
  } else if (!outputFile.getParentFile().exists()) {
   LOG.debug(String.format("Attempting to create output directory %s.",
   outputFileStream = new FileOutputStream(outputFile);
  } else {
   outputFileStream = new FileOutputStream(outputFile);
  IOUtils.copy(debInputStream, outputFileStream);
  outputFileStream.close();

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

counter = new CountingInputStream(new FileInputStream(inFile));
is = openArchiveStream(counter);
isTar = mCurrentTask.archiver.equals(archiveAlgorithm.tar);
  byte[] writeMe = null;
  outputStream = new FileOutputStream(f);
   writeMe = buffer = new byte[4];
   IOUtils.readFully(is, buffer);
    isScript = true;
    ByteArrayOutputStream firstLine = new ByteArrayOutputStream();
    int newline = -1;
     firstLine.write(buffer, 0, count);
   outputStream.write(writeMe);
  IOUtils.copy(is, outputStream);
  outputStream.close();
  outputStream = null;

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

assertNotNull(files);
for (final File file : files) {
 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (FileInputStream fis = new FileInputStream(file)) {
   try {
      IOUtils.copy(fis, baos);
    } catch (final Exception ex) {
      ex.printStackTrace();
  final String text = new String(baos.toByteArray(), Charset.defaultCharset());
  final String[] lines = text.split("[\\r\\n]+");
  for (final String line : lines) {

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

/**
 * Extracts the file contained in a gzip archive. The extracted file is
 * placed in the exact same path as the file specified.
 *
 * @param file the archive file
 * @throws FileNotFoundException thrown if the file does not exist
 * @throws IOException thrown if there is an error extracting the file.
 */
public static void extractGzip(File file) throws FileNotFoundException, IOException {
  final String originalPath = file.getPath();
  final File gzip = new File(originalPath + ".gz");
  if (gzip.isFile() && !gzip.delete()) {
    LOGGER.debug("Failed to delete initial temporary file when extracting 'gz' {}", gzip.toString());
    gzip.deleteOnExit();
  }
  if (!file.renameTo(gzip)) {
    throw new IOException("Unable to rename '" + file.getPath() + "'");
  }
  final File newFile = new File(originalPath);
  try (FileInputStream fis = new FileInputStream(gzip);
      GZIPInputStream cin = new GZIPInputStream(fis);
      FileOutputStream out = new FileOutputStream(newFile)) {
    IOUtils.copy(cin, out);
  } finally {
    if (gzip.isFile() && !org.apache.commons.io.FileUtils.deleteQuietly(gzip)) {
      LOGGER.debug("Failed to delete temporary file when extracting 'gz' {}", gzip.toString());
      gzip.deleteOnExit();
    }
  }
}

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

int gzippedFiles = 0;
for (final File file : files) {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  InputStream in = null;
  final FileExtension ext = FileExtension.lookupForFile(file.getName());
  try {
    try (FileInputStream fis = new FileInputStream(file)) {
      if (ext != null) {
        gzippedFiles++;
        try {
          in = new CompressorStreamFactory().createCompressorInputStream(ext.name().toLowerCase(),
              fis);
        } catch (final CompressorException ce) {
        in = new FileInputStream(file);
        IOUtils.copy(in, baos);
      } catch (final Exception ex) {
        ex.printStackTrace();
    Closer.close(in);
  final String text = new String(baos.toByteArray(), Charset.defaultCharset());
  final String[] lines = text.split("[\\r\\n]+");
  for (final String line : lines) {

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

public static void zip(String parentDir, String[] inputFiles, String outputFile)
  throws IOException {
 ZipOutputStream output = null;
 try {
  output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
  for (int i = 0; i < inputFiles.length; i++) {
   File f = new File(parentDir, inputFiles[i]);
   FileInputStream input = new FileInputStream(f);
   output.putNextEntry(new ZipEntry(inputFiles[i]));
   try {
    IOUtils.copy(input, output);
   } finally {
    input.close();
   }
  }
 } finally {
  org.apache.hadoop.io.IOUtils.closeStream(output);
 }
}

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

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

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

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

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

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

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

continue;
      OutputStream o = new FileOutputStream(outfile);
      try {
        IOUtils.copy(in, o);
      } finally {
        o.close();
  warInputStream.close();
} catch (FileNotFoundException e) {
  throw new TomcatSetupException(e.getMessage(), e);

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

private File compress(File file) throws IOException, CompressorException {
  final File output = new File(file.getParent(), file.getName() + ".gz");
  output.delete();
  final OutputStream out = new FileOutputStream(output);
  final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out);
  final FileInputStream is = new FileInputStream(file);
  IOUtils.copy(is, cos);
  is.close();
  cos.close();
  out.close();
  return output;
}

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

/**
 * Gets the contents of an <code>InputStream</code> as a <code>byte[]</code>.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 *
 * @param input  the <code>InputStream</code> to read from
 * @return the requested byte array
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @since 1.5
 */
public static byte[] toByteArray(final InputStream input) throws IOException {
  final ByteArrayOutputStream output = new ByteArrayOutputStream();
  copy(input, output);
  return output.toByteArray();
}

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

@Override
public ByteBuffer decompress(ByteBuffer compressedData) throws IOException {
  ByteArrayOutputStream baos = getOutputBuffer(compressedData.remaining());
  InputStream bytesIn = new ByteArrayInputStream(
   compressedData.array(),
   computeOffset(compressedData),
   compressedData.remaining());
  try (InputStream ios = new ZstdCompressorInputStream(bytesIn)) {
    IOUtils.copy(ios, baos);
  }
  return ByteBuffer.wrap(baos.toByteArray());
}

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

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

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

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

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

targetFile.createNewFile();
try (ArchiveOutputStream out = new ArchiveStreamFactory().createArchiveOutputStream(getExtension().getArchiveAs(), new FileOutputStream(targetFile, false))) {
  for (String includedFile : scanner.getIncludedFiles()) {
    LOGGER.debug("Adding file {}", includedFile);
    File f = source.resolve(includedFile).toFile();
    out.putArchiveEntry(buildArchiveEntry(f));
    IOUtils.copy(new FileInputStream(file), out);
    out.closeArchiveEntry();
  final String compressedTarget = targetFile.getAbsolutePath() + "." + getExtension().getCompressAs();
  LOGGER.quiet("Compress {}.", compressedTarget);
  try (FileOutputStream out = new FileOutputStream(compressedTarget, false)) {
    CompressorStreamFactory factory = new CompressorStreamFactory();
    try (CompressorOutputStream compressorStream = factory.createCompressorOutputStream(getExtension().getCompressAs(), out)) {
      IOUtils.copy(new FileInputStream(targetFile), compressorStream);

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

private void ar(File file, ArchiveOutputStream os) throws IOException {
  os.putArchiveEntry(new ArArchiveEntry(file.getName(), file.length()));
  final InputStream input = new FileInputStream(file);
  try {
    IOUtils.copy(input, os);
  } finally {
    input.close();
  }
  os.closeArchiveEntry();
}

相关文章