public class Zip
extends java.lang.Object
FileFunctions.addFilesWithBasePath(File, String, List)
.
Zip zip = new Zip(); //instance can be re-used in the same thread. zip.addSource(directory, path); zip.addSource(directory2, path2); String sError = zip.exec(dst, compressionLevel, comment); //the added sources are processed and removed. //next usage: zip.addSource(directory, path); String sError = zip.exec(dst, compressionLevel, comment);
Modifier and Type | Class and Description |
---|---|
static class |
Zip.Args
This class holds arguments to zip.
|
(package private) static class |
Zip.Src |
Modifier and Type | Field and Description |
---|---|
private boolean |
bsort |
private java.util.List<Zip.Src> |
listSrc |
private java.util.jar.Manifest |
manifest
A manifest file.
|
static java.lang.String |
version
Version, history and license.
|
Constructor and Description |
---|
Zip()
Creates an empty instance for Zip.
|
Modifier and Type | Method and Description |
---|---|
void |
addSource(java.io.File dir,
java.lang.String src)
Adds a source file or some files designated with wildcards
|
void |
addSource(java.lang.String src)
Adds a source file or some files designated with wildcards
|
java.lang.String |
exec(java.io.File fileZip,
int compressionLevel,
java.lang.String comment,
long timestamp)
Executes the creation of zip or jar with the given source files to a dst file.
|
java.lang.String |
exec(Zip.Args args)
Executes Zip with given arguments.
|
static void |
main(java.lang.String[] args)
Invocation from java command line
Zip routine from Java made by HSchorrig, 2013-02-09 - 2020-06-09
obligate arguments: -o:ZIP.zip { INPUT}
-compress:0..9 set the compression rate 0=non .. 9=max
-o:ZIP.zip file path for zip output
-sort sorts entries with path
-time:yyyy-MM-dd+hh:mm sets a timestamp for all entries in UTC (GMT)
-timeformat:yyyy-MM-dd+hh:mm is default, can define other format, see java.text.SimpleDataFormat
-manifest:
FileFunctions.addFilesWithBasePath(File, String, List)
|
void |
setManifest(java.io.File fileManifest)
Sets a manifest information from a given file.
|
static int |
smain(java.lang.String[] args)
Main routine able to call inside another java process without exit VM.
|
static void |
unzip(java.io.InputStream in) |
static java.lang.String |
zipfiles(java.io.File dst,
java.io.File srcdir,
java.lang.String sPath,
int compressionLevel,
java.lang.String comment)
Zips some files in a dst file.
|
public static final java.lang.String version
Cmdline#argList
now handled in MainCmd#setArguments(org.vishia.mainCmd.MainCmd.Argument[])
.
private final java.util.List<Zip.Src> listSrc
private java.util.jar.Manifest manifest
private boolean bsort
public Zip()
addSource(String)
or addSource(File, String)
and then #exec(File, int, String)
to create a Zipfile.
addSource(String)
and #exec(File, int, String)
with other files.
public void addSource(java.lang.String src)
src
- Path may contain the basebase:localpath separatet with ':'. The localpath is used inside the zip file
as file tree. The localpath may contain wildcards. The basepath may be an absolute path or it is located
in the systems current directory..
If the sPath does not contain a basepath (especially it is a simple path to a file), this path is used in the zipfile.
Especially the path can start from the current directory.
For usage of basepath, localpath and wildcards see FileFunctions.addFilesWithBasePath(File, String, List)
.public void addSource(java.io.File dir, java.lang.String src)
dir
- the directory where the source path starts.src
- Path may contain a basebase:localpath separatet with ':'. The localpath is used inside the zip file
as file tree. The localpath may contain wildcards.
If the sPath does not contain a basepath (especially it is a simple path to a file), this path is used in the zipfile.
For usage of basepath, localpath and wildcards see FileFunctions.addFilesWithBasePath(File, String, List)
.public void setManifest(java.io.File fileManifest) throws java.io.IOException
#exec(File, int, String)
, a jar file will be created
with this manifest. If the fileManifest does not contain a version info, the Attributes.Name#MANIFEST_VERSION
with the value "1.0" will be written.fileManifest
- a textual manifest file.java.io.IOException
- file not found, any file error.public java.lang.String exec(java.io.File fileZip, int compressionLevel, java.lang.String comment, long timestamp) throws java.io.IOException
setManifest(File)
was invoked before, a jar file will be created.
All source files should be set with addSource(File, String)
or addSource(String)
.fileZip
- The destination file.compressionLevel
- Level from 0..9 for compressioncomment
- in the zip file.java.io.IOException
- on any file error.
Note: If a given source file was not found, it was ignored but write as return hint.public static void unzip(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public java.lang.String exec(Zip.Args args) throws java.io.IOException
addSource(String)
before additional to the sources in add.
But usual the sources should be given only in args.
Zip zip = new Zip(); Zip.Args args = .... get args from somewhere zip.exec(args);
args
- java.io.IOException
public static java.lang.String zipfiles(java.io.File dst, java.io.File srcdir, java.lang.String sPath, int compressionLevel, java.lang.String comment) throws java.io.IOException
dst
- The destination file.sPath
- Path should contain the basebase:localpath separatet with ':'. The localpath is used inside the zip file
as file tree. For usage of basepath, localpath see FileFunctions.addFilesWithBasePath(File, String, List)
.compressionLevel
- Level from 0..9 for compressioncomment
- in the zip file.java.io.IOException
public static void main(java.lang.String[] args)
FileFunctions.addFilesWithBasePath(File, String, List)
args
- command line argumentspublic static int smain(java.lang.String[] args)
args
- cmd line args adequate main(String[])