Reads a gzipped tar archive from a stream and writes it to the given path.

@param dirPath the path to write the archive to
@param input the input stream
519694
public static void readTarGz(Path dirPath, InputStream input) throws IOException {
    InputStream zipStream = new GzipCompressorInputStream(input);
    TarArchiveInputStream archiveStream = new TarArchiveInputStream(zipStream);
    TarArchiveEntry entry;
    while ((entry = (TarArchiveEntry) archiveStream.getNextEntry()) != null) {
      File outputFile = new File(dirPath.toFile(), entry.getName());
      if (entry.isDirectory()) {
        outputFile.mkdirs();
      } else {
        outputFile.getParentFile().mkdirs();
        try (FileOutputStream fileOut = new FileOutputStream(outputFile)) {
          IOUtils.copy(archiveStream, fileOut);
        }
      }
    }
  }
527122
public void setInput(final String inputPath) {
        if (inputPath == null) {
            throw (new IllegalArgumentException(
                    "You must provide a source folder or file"));
        }
        File inputFile = new File(inputPath);
        if (inputFile.exists()) {
            if (inputFile.isDirectory() && inputFile.list().length == 0) {
                throw new IllegalArgumentException("Folder '" + inputPath
                        + "' is empty");
            }
        } else {
            throw new IllegalArgumentException("Input file or folder '"
                    + inputPath + "' not found");
        }
        this.input = inputFile;
    }
1127484
def open_archive(stream, filename):
    
    name, ext = os.path.splitext(os.path.basename(filename))

    def targz_handler(stream):
        return TarGZAdapter(tarfile.open(fileobj=stream, mode='r:gz'))
    cls = [zipfile.ZipFile, targz_handler]['gz' in ext]
    archive = cls(stream)
    return archive
400440
public static void write(InputStream in, Path path) {
        write(in, path, StandardCopyOption.REPLACE_EXISTING);
    }
65822
public void setInput(final InputStream input, final boolean binary)
		throws IOException
	{

		if (!binary) {

			int v = input.read();
			StringBuilder buffer = new StringBuilder();

			// Check for the no-zip flag
			boolean zipFlag = (char) v == '_';
			if (zipFlag) {
				v = input.read();
			}

			while (v != -1) {
				buffer.append((char) v);
				v = input.read();
			}

			if (zipFlag) {
				r = new BitReader(inflateInput(
						Base64.decodeBase64(buffer.toString()), 0));
			}
			else {
				r = new BitReader(Base64.decodeBase64(buffer.toString()));
			}
		}
		else {

			ByteArrayOutputStream stream = new ByteArrayOutputStream();

			byte[] bData;
			int l = input.available();
			while (l != 0) {

				bData = new byte[l];

				if (input.read(bData) != l) {
					throw new RuntimeException("ILLEGAL NUMBER OF BYTES READ");
				}
				stream.write(bData);

				l = input.available();
			}

			if (input.read() != -1) {
				throw new RuntimeException("END OF STREAM NOT REACHED");
			}

			bData = stream.toByteArray();

			boolean zipFlag = bData[0] == -128;

			if (zipFlag) {
				r = new BitReader(inflateInput(bData, 1));
			}
			else {
				r = new BitReader(bData);
			}
		}
	}
101306
public OutputStream getCompressionStream(String path)
		throws IOException
	{
		File archivedFile = new File(path);

		archivedFile.createNewFile();

		FileOutputStream fos = new FileOutputStream(archivedFile);

		BufferedOutputStream bufStr = new BufferedOutputStream(fos);
		// added bzip2 prefix
		fos.write("BZ".getBytes());

		CBZip2OutputStream bzip2 = new CBZip2OutputStream(bufStr);
		return bzip2;
	}
305436
public void compress(Stream<Path> paths) throws IOException
    {
        boolean first = true;
        Iterator<Path> it = paths.iterator();
        while (it.hasNext())
        {
            Path p = it.next();
            if (Files.isRegularFile(path))
            {
                setFilename(p.getFileName().toString());
                setLastModified(Files.getLastModifiedTime(p));
                if (!first)
                {
                    nextOutput();
                }
                first = false;
                OutputStream os = Channels.newOutputStream(this);
                Files.copy(p, os);
            }
            else
            {
                throw new IOException(p+" is not a regular file");
            }
        }
        close();
    }
114197
protected static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
		byte[] bytesIn = new byte[BUFFER_SIZE];
		int read = 0;
		while ((read = zipIn.read(bytesIn)) != -1) {
			bos.write(bytesIn, 0, read);
		}
		bos.close();
	}
285911
def _generate_tar(dir_path):
    """"""
    try:
        with tarfile.open(dir_path + '.tar', 'w') as tar:
            tar.add(dir_path)
    except tarfile.TarError as e:
        stderr("Error: tar archive creation failed [" + str(e) + "]", exit=1)
1015512
private static BufferedReader open(final String path) throws IOException {
    if (path.equals("-")) {
      return new BufferedReader(new InputStreamReader(System.in));
    }

    InputStream is = new FileInputStream(path);
    if (path.endsWith(".gz")) {
      is = new GZIPInputStream(is);
    }
    // I <3 Java's IO library.
    return new BufferedReader(new InputStreamReader(is));
  }
1237422
private static void compressDirectory(String relativePath, File srcPath, ZipOutputStream zip) throws IOException
   {
      if (srcPath.isDirectory())
      {
         zip.putNextEntry(new ZipEntry(relativePath + "/" + srcPath.getName() + "/"));
         zip.closeEntry();

         String files[] = srcPath.list();
         for (int i = 0; i < files.length; i++)
         {
            compressDirectory(relativePath + "/" + srcPath.getName(), new File(srcPath, files[i]), zip);
         }
      }
      else
      {
         InputStream in = new FileInputStream(srcPath);
         try
         {
            zip.putNextEntry(new ZipEntry(relativePath + "/" + srcPath.getName()));

            transfer(in, zip);

            zip.closeEntry();
         }
         finally
         {
            if (in != null)
            {
               in.close();
            }
         }
      }
   }
46512
public static boolean coreExpandArchive(String sourcePath, String targetPath) throws IOException {
        ZipArchiveInputStream in = null;
        OutputStream out = null;

        try {

            // make sure we're working with absolute canonical paths
            File source = new File(sourcePath).getCanonicalFile();
            File target = new File(targetPath).getCanonicalFile();

            // open the archive
            in = new ZipArchiveInputStream(getInputStream(source));

            // expand all entries of the archive
            for (ZipArchiveEntry entry = in.getNextZipEntry(); entry != null; entry = in.getNextZipEntry()) {

                // get the pathname of the entry (this will be a relative path)
                String outFilename = entry.getName();

                // construct the absolute path of where this entry will be expanded
                String targetPlusOutFile = target.getPath() + File.separator + outFilename;

                File targetFile = new File(targetPlusOutFile);
                char ending = outFilename.charAt(outFilename.length() - 1);

                if (ending == '/' || ending == '\\') {
                    fileMkDirs(targetFile);
                    if (helper != null) {
                        helper.setPermissions(targetFile, entry.getUnixMode());
                    }
                    continue;
                } else {
                    fileMkDirs(targetFile.getParentFile());
                }

                // expand the entry
                out = getOutputStream(targetFile);
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }

                // Close the streams
                out.close();

                if (helper != null) {
                    helper.setPermissions(targetFile, entry.getUnixMode());
                }

                out = null;
            }
            in.close();
            in = null;

            return true;

        } catch (IOException e) {
            throw e;
        } finally {
            // try to close any open files
            tryToClose(out);
            tryToClose(in);
        }
    }
576725
@Override
    protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
            long lastModified, File fromArchive, int mode) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IoUtil.copy(is, baos, buf);
        struct.data = baos.toByteArray();
        struct.name = vPath;
        struct.time = lastModified;
        if (proc.process(struct) != JarProcessor.Result.DISCARD) {
            if (mode == 0)
                mode = ZipFileSet.DEFAULT_FILE_MODE;
            if (!filesOnly) {
                addParentDirs(struct.name, zOut);
            }
            super.zipFile(new ByteArrayInputStream(struct.data),
                    zOut, struct.name, struct.time, fromArchive, mode);
        }
    }
247531
private static void addDir(File dirObj, ZipOutputStream out)
            throws IOException {
        File[] dirList = dirObj.listFiles();
        byte[] tmpBuf = new byte[1024];

        for (int i = 0; i < dirList.length; i++) {
            if (dirList[i].isDirectory()) {
                addDir(dirList[i], out);
                continue;
            }

            FileInputStream in = new FileInputStream(
                    dirList[i].getAbsolutePath());
            System.out.println(" Adding: " + dirList[i].getAbsolutePath());

            out.putNextEntry(new ZipEntry(dirList[i].getAbsolutePath()));

            // Transfer from the file to the ZIP file
            int len;
            while ((len = in.read(tmpBuf)) > 0) {
                out.write(tmpBuf, 0, len);
            }

            // Complete the entry
            out.closeEntry();
            in.close();
        }
    }
242813
public static void createZip(String sourcePath, String zipPath) {
        FileOutputStream fos = null;
        ZipOutputStream zos = null;
        try {
            fos = new FileOutputStream(zipPath);
            zos = new ZipOutputStream(fos);
            writeZip(new File(sourcePath), "", zos);
        } catch (FileNotFoundException e) {
            LOG.error("创建ZIP文件失败",e);
        } finally {
            try {
                if (zos != null) {
                    zos.close();
                }
            } catch (IOException e) {
                LOG.error("创建ZIP文件失败",e);
            }

        }
    }
521247
public ZipStreamImpl openReadImpl(PathImpl path) 
    throws IOException
  {
    String pathName = path.getPath();
    
    return openReadImpl(pathName);
  }
1329881
public static void unzipToFolder(File inputFile, File outputDir) throws IOException
    {
        if (inputFile == null)
            throw new IllegalArgumentException("Argument inputFile is null.");
        if (outputDir == null)
            throw new IllegalArgumentException("Argument outputDir is null.");

        try (ZipFile zipFile = new ZipFile(inputFile))
        {
            Enumeration<? extends ZipEntry> entryEnum = zipFile.entries();
            while (entryEnum.hasMoreElements())
            {
                ZipEntry entry = entryEnum.nextElement();
                String entryName = entry.getName();
                File destFile = new File(outputDir, entryName);
                if (!entry.isDirectory())
                {
                    File parentDir = destFile.getParentFile();
                    if (!parentDir.isDirectory() && !parentDir.mkdirs())
                    {
                        throw new WindupException("Unable to create directory: " + parentDir.getAbsolutePath());
                    }
                    try (InputStream zipInputStream = zipFile.getInputStream(entry))
                    {
                        try (FileOutputStream outputStream = new FileOutputStream(destFile))
                        {
                            Streams.write(zipInputStream, outputStream);
                        }
                    }
                }
            }
        }
    }