Changes a zip file, adds one new entry in-place.

@param zip
an existing ZIP file (only read).
@param path
new ZIP entry path.
@param bytes
new entry bytes (or <code>null</code> if directory).
167966
public static void addEntry(final File zip, final String path, final byte[] bytes) {
    operateInPlace(zip, new InPlaceAction() {
      public boolean act(File tmpFile) {
        addEntry(zip, path, bytes, tmpFile);
        return true;
      }
    });
  }
534547
protected void addToZip(final String path, final String file, BuildData buildData) throws BuildProcessingException {
        try {
            buildData.getOutputFiles().put(path, file.getBytes(ENCODING));
        } catch (UnsupportedEncodingException e) {
            /* UTF-8 is a valid format so this should exception should never get thrown */
            throw new BuildProcessingException(e);
        }
    }
470029
public static void setBytes(Path self, byte[] bytes) throws IOException {
        IOGroovyMethods.setBytes(Files.newOutputStream(self), bytes);
    }
1106845
private static void addDir(String path, ZipOutputStream out) throws UtilException {
		path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
		try {
			out.putNextEntry(new ZipEntry(path));
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			closeEntry(out);
		}
	}
1352738
public static void unzip(Path zip, Path target) throws IOException {
        try (final ZipFile zipFile = new ZipFile(zip.toFile())){
            unzip(zipFile, target);
        }
    }
948723
public String []list(String path) throws IOException
  {
    if (path.startsWith("/")) {
      path = path.substring(1);
    }
    
    if (! path.endsWith("/")) {
      path = path + "/";
    }

    ArrayList<String> names = new ArrayList<>();
    
    ZipFile zipFile = getZipFile();
    
    try {
      Enumeration<? extends ZipEntry> e = zipFile.entries();
      
      while (e.hasMoreElements()) {
        ZipEntry entry = e.nextElement();
        
        String name = entry.getName();

        if (name.startsWith(path)) {
          String tail = name.substring(path.length());
          int p = tail.indexOf('/');
          
          if (p >= 0) {
            tail = tail.substring(0, p);
          }
          
          if (! tail.equals("") && ! names.contains(tail)) {
            names.add(tail);
          }
        }
      }
    } finally {
      closeZipFile(zipFile);
    }
    
    String []list = new String[names.size()];
    
    names.toArray(list);
    
    return list;
  }
1098745
public Jar addEntry(String path, byte[] content) throws IOException {
        beginWriting();
        addEntry(jos, path, content);
        return this;
    }
521247
public ZipStreamImpl openReadImpl(PathImpl path) 
    throws IOException
  {
    String pathName = path.getPath();
    
    return openReadImpl(pathName);
  }
1082693
public void decompress(String path)
		throws IOException
	{
		File bzip2 = new File(path);

		//
		File unarchived = new File(bzip2.getName().replace(".bz2", ""));

		unarchived.createNewFile();

		BufferedInputStream inputStr = new BufferedInputStream(new FileInputStream(bzip2));

		// read bzip2 prefix
		inputStr.read();
		inputStr.read();

		BufferedInputStream buffStr = new BufferedInputStream(inputStr);

		CBZip2InputStream input = new CBZip2InputStream(buffStr);

		FileOutputStream outStr = new FileOutputStream(unarchived);

		while (true) {
			byte[] compressedBytes = new byte[DECOMPRESSION_CACHE];

			int byteRead = input.read(compressedBytes);

			outStr.write(compressedBytes, 0, byteRead);
			if (byteRead != DECOMPRESSION_CACHE) {
				break;
			}
		}

		input.close();
		buffStr.close();
		inputStr.close();
		outStr.close();
	}
776177
public static final boolean isArchive(Path path) throws IOException {
        if (Files.exists(path) && Files.isRegularFile(path)) {
            try (ZipFile zip = new ZipFile(path.toFile())){
                return true;
            } catch (ZipException e) {
                return false;
            }
        }
        return false;
    }
494801
public void writeEntry(String path, ByteSource contents) throws IOException {
    stream.putNextEntry(new ZipEntry(path));
    contents.copyTo(stream);
    stream.closeEntry();
  }
965567
private static void addFile(InputStream in, String path, ZipOutputStream out) throws UtilException {
		if (null == in) {
			return;
		}
		try {
			out.putNextEntry(new ZipEntry(path));
			IoUtil.copy(in, out);
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			closeEntry(out);
		}
	}
645498
private function addFiles($zip, $path = null)
	{
		if (!$path)
		{
			$path = $this->current;
		}

		$source = str_replace('\\', '/', realpath($path));

		if (is_dir($source) === true)
		{
			$files = new \RecursiveIteratorIterator(
				new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST
			);

			foreach ($files as $file)
			{
				$file = str_replace('\\', '/', $file);

				if (substr($file, 0, 1) == ".")
				{
					continue;
				}

				// Ignore "." and ".." folders
				if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')))
				{
					continue;
				}

				$file = str_replace('\\', '/', $file);

				if (is_dir($file) === true)
				{
					$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
				}
				else if (is_file($file) === true)
				{
					$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
				}
			}
		}
		else if (is_file($source) === true)
		{
			$zip->addFromString(basename($source), file_get_contents($source));
		}
	}
24218
public static boolean transformEntry(final File zip, final String path, final ZipEntryTransformer transformer) {
    return operateInPlace(zip, new InPlaceAction() {
      public boolean act(File tmpFile) {
        return transformEntry(zip, path, transformer, tmpFile);
      }
    });
  }
495573
public ZipMessage addEntry(String fileName, byte[] content) {
        Entry entry = new Entry(fileName);
        entry.setContent(content);
        addEntry(entry);
        return this;
    }
1084930
public void addFile(String path, File file) throws IOException {
    addFile(path, file, null);
  }
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);
        }
    }