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.
Multi volume archives can be read by concatenating the parts in correct order - either manually or by using {link org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel} for example.
| Modifier and Type | Class and Description |
|---|---|
static class |
SevenZFile.Builder
Builds new instances of
SevenZFile. |
| Constructor and Description |
|---|
SevenZFile(java.io.File fileName)
Deprecated.
|
SevenZFile(java.io.File file,
byte[] password)
Deprecated.
|
SevenZFile(java.io.File file,
char[] password)
Deprecated.
|
SevenZFile(java.io.File file,
char[] password,
SevenZFileOptions options)
Deprecated.
|
SevenZFile(java.io.File file,
SevenZFileOptions options)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
byte[] password)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
char[] password)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
char[] password,
SevenZFileOptions options)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
SevenZFileOptions options)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
byte[] password)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
char[] password)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
char[] password,
SevenZFileOptions options)
Deprecated.
|
SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
SevenZFileOptions options)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static SevenZFile.Builder |
builder()
Creates a new Builder.
|
void |
close()
Closes the archive.
|
java.lang.String |
getDefaultName()
Gets a default file name from the archive name - if known.
|
java.lang.Iterable<SevenZArchiveEntry> |
getEntries()
Gets a copy of meta-data of all archive entries.
|
java.io.InputStream |
getInputStream(SevenZArchiveEntry entry)
Gets an InputStream for reading the contents of the given entry.
|
SevenZArchiveEntry |
getNextEntry()
Gets the next Archive Entry in this archive.
|
InputStreamStatistics |
getStatisticsForCurrentEntry()
Gets statistics for bytes read from the current entry.
|
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.
|
java.lang.String |
toString() |
@Deprecated
public SevenZFile(java.io.File fileName)
throws java.io.IOException
SevenZFile.Builder.get().fileName - the file to read.java.io.IOException - if reading the archive fails.@Deprecated
public SevenZFile(java.io.File file,
byte[] password)
throws java.io.IOException
SevenZFile.Builder.get().file - 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 fails@Deprecated
public SevenZFile(java.io.File file,
char[] password)
throws java.io.IOException
SevenZFile.Builder.get().file - the file to readpassword - optional password if the archive is encryptedjava.io.IOException - if reading the archive fails@Deprecated
public SevenZFile(java.io.File file,
char[] password,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().file - the file to readpassword - optional password if the archive is encryptedoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too small@Deprecated
public SevenZFile(java.io.File file,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().file - the file to readoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too small@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readjava.io.IOException - if reading the archive fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
byte[] password)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel 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 fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
char[] password)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readpassword - optional password if the archive is encryptedjava.io.IOException - if reading the archive fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
char[] password,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readpassword - optional password if the archive is encryptedoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too small@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too small@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readfileName - name of the archive - only used for error reportingjava.io.IOException - if reading the archive fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
byte[] password)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readfileName - name of the archive - only used for error reportingpassword - 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 fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
char[] password)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readfileName - name of the archive - only used for error reportingpassword - optional password if the archive is encryptedjava.io.IOException - if reading the archive fails@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
char[] password,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readfileName - name of the archive - only used for error reportingpassword - optional password if the archive is encryptedoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too small@Deprecated
public SevenZFile(java.nio.channels.SeekableByteChannel channel,
java.lang.String fileName,
SevenZFileOptions options)
throws java.io.IOException
SevenZFile.Builder.get().
SeekableInMemoryByteChannel allows you to read from an in-memory archive.
channel - the channel to readfileName - name of the archive - only used for error reportingoptions - the options to applyjava.io.IOException - if reading the archive fails or the memory limit (if set) is too smallpublic static SevenZFile.Builder builder()
public static boolean matches(byte[] signature,
int length)
signature - the bytes to checklength - the number of bytes to checkpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException - if closing the file failspublic java.lang.String getDefaultName()
This implements the same heuristics the 7z tools use. In 7z's case if an archive contains entries without a name - i.e.
SevenZArchiveEntry.getName() returns null - then its command line and GUI tools will use this default name when extracting the entries.
~ character is appended to the archive name.public java.lang.Iterable<SevenZArchiveEntry> getEntries()
This method only provides meta-data, the entries can not be used to read the contents, you still need to process all entries in order using
getNextEntry() for that.
The content methods are only available for entries that have already been reached via getNextEntry().
public java.io.InputStream getInputStream(SevenZArchiveEntry entry) throws java.io.IOException
For archives using solid compression randomly accessing entries will be significantly slower than reading the archive sequentially.
entry - the entry to get the stream for.java.io.IOException - if unable to create an input stream from the entrypublic SevenZArchiveEntry getNextEntry() throws java.io.IOException
null if there are no more entriesjava.io.IOException - if the next entry could not be readpublic InputStreamStatistics getStatisticsForCurrentEntry()
public 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 java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2010 - 2024 Adobe. All Rights Reserved