public class SevenZFile
extends java.lang.Object
implements java.io.Closeable
The 7z file format is a flexible container that can contain many compression and encryption types, but at the moment only only Copy, LZMA, LZMA2, BZIP2, Deflate and AES-256 + SHA-256 are supported.
The format is very Windows/Intel specific, so it uses little-endian byte order, doesn't store user/group or permission bits, and represents times using NTFS timestamps (100 nanosecond units since 1 January 1601). Hence the official tools recommend against using it for backup purposes on *nix, and recommend .tar.7z or .tar.lzma or .tar.xz instead.
Both the header and file contents may be compressed and/or encrypted. With both encrypted, neither file names nor file contents can be read, but the use of encryption isn't plausibly deniable.
| Constructor and Description |
|---|
SevenZFile(java.io.File filename)
Reads a file as unecrypted 7z archive
|
SevenZFile(java.io.File filename,
byte[] password)
Reads a file as 7z archive
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the archive.
|
SevenZArchiveEntry |
getNextEntry()
Returns the next Archive Entry in this archive.
|
static boolean |
matches(byte[] signature,
int length)
Checks if the signature matches what is expected for a 7z file.
|
int |
read()
Reads a byte of data.
|
int |
read(byte[] b)
Reads data into an array of bytes.
|
int |
read(byte[] b,
int off,
int len)
Reads data into an array of bytes.
|
public SevenZFile(java.io.File filename,
byte[] password)
throws java.io.IOException
filename - the file to readpassword - optional password if the archive is encrypted -
the byte array is supposed to be the UTF16-LE encoded
representation of the password.java.io.IOException - if reading the archive failspublic SevenZFile(java.io.File filename)
throws java.io.IOException
filename - the file to readjava.io.IOException - if reading the archive failspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException - if closing the file failspublic SevenZArchiveEntry getNextEntry() throws java.io.IOException
null if there are no more entriesjava.io.IOException - if the next entry could not be readpublic int read()
throws java.io.IOException
java.io.IOException - if an I/O error has occurredpublic int read(byte[] b)
throws java.io.IOException
b - the array to write data tojava.io.IOException - if an I/O error has occurredpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
b - the array to write data tooff - offset into the buffer to start filling atlen - of bytes to readjava.io.IOException - if an I/O error has occurredpublic static boolean matches(byte[] signature,
int length)
signature - the bytes to checklength - the number of bytes to check