public class SevenZOutputFile extends Object implements Closeable
| Constructor and Description |
|---|
SevenZOutputFile(File fileName)
Opens file to write a 7z archive to.
|
SevenZOutputFile(SeekableByteChannel channel)
Prepares channel to write a 7z archive to.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the archive, calling
finish() if necessary. |
void |
closeArchiveEntry()
Closes the archive entry.
|
SevenZArchiveEntry |
createArchiveEntry(File inputFile,
String entryName)
Create an archive entry using the inputFile and entryName provided.
|
SevenZArchiveEntry |
createArchiveEntry(Path inputPath,
String entryName,
LinkOption... options)
Create an archive entry using the inputPath and entryName provided.
|
void |
finish()
Finishes the addition of entries to this archive, without closing it.
|
void |
putArchiveEntry(ArchiveEntry archiveEntry)
Records an archive entry to add.
|
void |
setContentCompression(SevenZMethod method)
Sets the default compression method to use for entry contents - the
default is LZMA2.
|
void |
setContentMethods(Iterable<? extends SevenZMethodConfiguration> methods)
Sets the default (compression) methods to use for entry contents - the
default is LZMA2.
|
void |
write(byte[] b)
Writes a byte array to the current archive entry.
|
void |
write(byte[] b,
int off,
int len)
Writes part of a byte array to the current archive entry.
|
void |
write(InputStream inputStream)
Writes all of the given input stream to the current archive entry.
|
void |
write(int b)
Writes a byte to the current archive entry.
|
void |
write(Path path,
OpenOption... options)
Writes all of the given input stream to the current archive entry.
|
public SevenZOutputFile(File fileName) throws IOException
fileName - the file to write toIOException - if opening the file failspublic SevenZOutputFile(SeekableByteChannel channel) throws IOException
SeekableInMemoryByteChannel
allows you to write to an in-memory archive.
channel - the channel to write toIOException - if the channel cannot be positioned properlypublic void setContentCompression(SevenZMethod method)
Currently only SevenZMethod.COPY, SevenZMethod.LZMA2, SevenZMethod.BZIP2 and SevenZMethod.DEFLATE are supported.
This is a short form for passing a single-element iterable
to setContentMethods(java.lang.Iterable<? extends org.apache.commons.compress.archivers.sevenz.SevenZMethodConfiguration>).
method - the default compression methodpublic void setContentMethods(Iterable<? extends SevenZMethodConfiguration> methods)
Currently only SevenZMethod.COPY, SevenZMethod.LZMA2, SevenZMethod.BZIP2 and SevenZMethod.DEFLATE are supported.
The methods will be consulted in iteration order to create the final output.
methods - the default (compression) methodspublic void close() throws IOException
finish() if necessary.close in interface Closeableclose in interface AutoCloseableIOException - on errorpublic SevenZArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException
inputFile - file to create an entry fromentryName - the name to useIOException - on errorpublic SevenZArchiveEntry createArchiveEntry(Path inputPath, String entryName, LinkOption... options) throws IOException
inputPath - path to create an entry fromentryName - the name to useoptions - options indicating how symbolic links are handled.IOException - on errorpublic void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException
closeArchiveEntry() to complete the process.archiveEntry - describes the entryIOException - on errorpublic void closeArchiveEntry() throws IOException
IOException - on errorpublic void write(int b) throws IOException
b - The byte to be written.IOException - on errorpublic void write(byte[] b) throws IOException
b - The byte array to be written.IOException - on errorpublic void write(byte[] b, int off, int len) throws IOException
b - The byte array to be written.off - offset into the array to start writing fromlen - number of bytes to writeIOException - on errorpublic void write(InputStream inputStream) throws IOException
inputStream - the data source.IOException - if an I/O error occurs.public void write(Path path, OpenOption... options) throws IOException
path - the data source.options - options specifying how the file is opened.IOException - if an I/O error occurs.public void finish() throws IOException
IOException - if archive is already closed.Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.