Package com.diffplug.gradle
Class ZipMisc
- java.lang.Object
-
- com.diffplug.gradle.ZipMisc
-
public class ZipMisc extends Object
Utilities for mucking with zip files.
-
-
Constructor Summary
Constructors Constructor Description ZipMisc()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmodify(com.diffplug.common.io.ByteSource input, com.diffplug.common.io.ByteSink output, Map<String,Function<byte[],byte[]>> toModify, Predicate<String> toOmit)Modifies only the specified entries in a zip file.static voidmodify(File file, Map<String,Function<byte[],byte[]>> toModify, Predicate<String> toOmit)Modifies a file in-place.static Stringread(File input, String toRead)Reads the given entry from the zip.static voidread(File input, String toRead, com.diffplug.common.base.Throwing.Specific.Consumer<InputStream,IOException> reader)Reads the given entry from the zip.static voidunzip(File input, File destinationDir)Unzips a directory to a folder.static voidzip(File input, String pathWithinArchive, File output)Creates a single-entry zip file.
-
-
-
Method Detail
-
read
public static void read(File input, String toRead, com.diffplug.common.base.Throwing.Specific.Consumer<InputStream,IOException> reader) throws IOException
Reads the given entry from the zip.- Parameters:
input- a zip filetoRead- a path within that zip filereader- will be called with an InputStream containing the contents of that entry in the zip file- Throws:
IOException
-
read
public static String read(File input, String toRead) throws IOException
Reads the given entry from the zip.- Parameters:
input- a zip filetoRead- a path within that zip file- Returns:
- the given path within the zip file decoded as a UTF8 string, with only unix newlines.
- Throws:
IOException
-
modify
public static void modify(com.diffplug.common.io.ByteSource input, com.diffplug.common.io.ByteSink output, Map<String,Function<byte[],byte[]>> toModify, Predicate<String> toOmit) throws IOExceptionModifies only the specified entries in a zip file.- Parameters:
input- a source from a zip fileoutput- an output to a zip filetoModify- a map from path to an input stream for the entries you'd like to changetoOmit- a set of entries you'd like to leave out of the zip- Throws:
IOException
-
modify
public static void modify(File file, Map<String,Function<byte[],byte[]>> toModify, Predicate<String> toOmit) throws IOException
Modifies a file in-place.- Throws:
IOException
-
zip
public static void zip(File input, String pathWithinArchive, File output) throws IOException
Creates a single-entry zip file.- Parameters:
input- an uncompressed filepathWithinArchive- the path within the archiveoutput- the new zip file it will be compressed into- Throws:
IOException
-
unzip
public static void unzip(File input, File destinationDir) throws IOException
Unzips a directory to a folder.- Parameters:
input- a zip filedestinationDir- where the zip will be extracted to- Throws:
IOException
-
-