Package VASSAL.tools.io
Class ZipArchive
java.lang.Object
VASSAL.tools.io.ZipArchive
- All Implemented Interfaces:
Closeable,AutoCloseable,FileArchive
- Since:
- 3.2.0
- Author:
- Joel Uckelman
-
Constructor Summary
ConstructorsConstructorDescriptionZipArchive(File file) Opens a ZIP archive.ZipArchive(File file, boolean truncate) Opens a ZIP archive.ZipArchive(String path) Opens a ZIP archive.ZipArchive(String path, boolean truncate) Opens a ZIP archive.ZipArchive(Path path, boolean truncate) Opens a ZIP archive.ZipArchive(FileArchive src, File dst) Copies a ZIP archive.ZipArchive(FileArchive src, String dst) Copies a ZIP archive.ZipArchive(FileArchive src, Path dst) Copies a ZIP archive. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the contents of a byte array to the archive.voidAdds a file to the archive.voidadd(String path, InputStream in) Adds the contents of anInputStreamto the archive.voidAdds a file to the archive.voidclose()Closes the archive, writing all changes to disk.booleanQueries whether a file exists in the archive.voidflush()Forces all changes to the archive to disk.longgetCompressedSize(String path) Get the compressed size of a file in the archive, in bytes.getFile()Gets the path to the archive file.getFiles()Gets the list of files in the archive.Gets the list of files under a given directory of the archive.getInputStream(String path) Gets anInputStreamto read from the given file.longGets the modification time of a file in the archive, in milliseconds since the epoch.getName()Gets the path to the archive file.getOutputStream(String path) Gets anOutputStreamto write to the given file.getOutputStream(String path, boolean compress) Gets anOutputStreamto write to the given file.getPath()longGets the size of a file in the archive, in bytes.booleanisClosed()Queries whether the archive is closed.booleanQueries whether the archive has unsaved modifications.booleanRemoves a file from the archive.voidrevert()Reverts the archive to its last saved state.
-
Constructor Details
-
ZipArchive
Opens a ZIP archive.- Parameters:
path- the name of the archive- Throws:
IOException- oops
-
ZipArchive
Opens a ZIP archive.- Parameters:
file- the name of the archive- Throws:
IOException- oops
-
ZipArchive
Opens a ZIP archive.- Parameters:
path- the name of the archivetruncate- iftrue, truncate the archive file on open- Throws:
IOException- oops
-
ZipArchive
Opens a ZIP archive.- Parameters:
file- the name of the archivetruncate- iftrue, truncate the archive file on open- Throws:
IOException- oops
-
ZipArchive
Opens a ZIP archive.- Parameters:
path- the name of the archivetruncate- iftrue, truncate the archive file on open- Throws:
IOException- oops
-
ZipArchive
Copies a ZIP archive.- Parameters:
src- the name of the source archivedst- the name of the destination archive- Throws:
IOException- oops
-
ZipArchive
Copies a ZIP archive.- Parameters:
src- the name of the source archivedst- the name of the destination archive- Throws:
IOException- oops
-
ZipArchive
Copies a ZIP archive.- Parameters:
src- the name of the source archivedst- the name of the destination archive- Throws:
IOException- oops
-
-
Method Details
-
getName
Gets the path to the archive file.- Specified by:
getNamein interfaceFileArchive- Returns:
- the path as a
String
-
getFile
Gets the path to the archive file.- Specified by:
getFilein interfaceFileArchive- Returns:
- the path as a
File
-
getPath
-
isClosed
public boolean isClosed()Queries whether the archive is closed.- Specified by:
isClosedin interfaceFileArchive- Returns:
trueif the archive is closed
-
isModified
public boolean isModified()Queries whether the archive has unsaved modifications.- Specified by:
isModifiedin interfaceFileArchive- Returns:
trueif the archive is modified
-
getInputStream
Gets anInputStreamto read from the given file. Note: It is imperative the that calling code ensures that this stream is eventually closed, since the returned stream holds a read lock on the archive.- Specified by:
getInputStreamin interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
- an
InputStreamcontaining the requested file - Throws:
IOException- oops
-
getOutputStream
Gets anOutputStreamto write to the given file. Note: It is imperative the that calling code ensures that this stream is eventually closed, since the returned stream holds a write lock on the archive.- Specified by:
getOutputStreamin interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
- an
OutputStreamfor the requested file - Throws:
IOException- oops
-
getOutputStream
Gets anOutputStreamto write to the given file. Note: It is imperative the that calling code ensures that this stream is eventually closed, since the returned stream holds a write lock on the archive.- Parameters:
path- the path to the file in the archivecompress- whether to compress the file- Returns:
- an
OutputStreamfor the requested file - Throws:
IOException- oops
-
add
Adds a file to the archive.- Specified by:
addin interfaceFileArchive- Parameters:
path- the internal path of the file to be addedextPath- the external path of the file to be added- Throws:
IOException- oops
-
add
Adds a file to the archive.- Specified by:
addin interfaceFileArchive- Parameters:
path- the internal path of the file to be addedextPath- the external path to the file to be added- Throws:
IOException- oops
-
add
Adds the contents of a byte array to the archive.- Specified by:
addin interfaceFileArchive- Parameters:
path- the internal path of the file to be addedbytes- the bytes to be added- Throws:
IOException- oops
-
add
Adds the contents of anInputStreamto the archive.- Specified by:
addin interfaceFileArchive- Parameters:
path- the internal path of the file to be addedin- theInputStreamto read from- Throws:
IOException- oops
-
remove
Removes a file from the archive.- Specified by:
removein interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
trueif the file existed in the archive- Throws:
IOException- oops
-
revert
Reverts the archive to its last saved state.- Specified by:
revertin interfaceFileArchive- Throws:
IOException- oops
-
flush
Forces all changes to the archive to disk.- Specified by:
flushin interfaceFileArchive- Throws:
IOException- oops
-
close
Closes the archive, writing all changes to disk.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceFileArchive- Throws:
IOException- oops
-
contains
Queries whether a file exists in the archive.- Specified by:
containsin interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
trueif the file exists in the archive- Throws:
IOException- oops
-
getSize
Gets the size of a file in the archive, in bytes.- Specified by:
getSizein interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
- the size of the file, in bytes
- Throws:
IOException- oops
-
getCompressedSize
Get the compressed size of a file in the archive, in bytes. Rerurn the uncompressed size by default.- Specified by:
getCompressedSizein interfaceFileArchive- Returns:
- the compressed size of the file, in bytes
- Throws:
IOException- oops
-
getMTime
Gets the modification time of a file in the archive, in milliseconds since the epoch.- Specified by:
getMTimein interfaceFileArchive- Parameters:
path- the path to the file in the archive- Returns:
- the mtime of the file
- Throws:
IOException- oops
-
getFiles
Gets the list of files in the archive.- Specified by:
getFilesin interfaceFileArchive- Returns:
- the list of files in the archive
- Throws:
IOException- oops
-
getFiles
Gets the list of files under a given directory of the archive.- Specified by:
getFilesin interfaceFileArchive- Parameters:
root- the directory- Returns:
- the list of files under the given directory
- Throws:
IOException- oops
-