Class ArArchiveOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.compress.archivers.ArchiveOutputStream
-
- org.apache.commons.compress.archivers.ar.ArArchiveOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class ArArchiveOutputStream extends ArchiveOutputStream
Implements the "ar" archive format as an output stream.
-
-
Field Summary
Fields Modifier and Type Field Description private longentryOffsetprivate booleanfinishedindicates if this archive is finishedprivate booleanhaveUnclosedEntrystatic intLONGFILE_BSDBSD ar extensions are used to store long file names in the archive.static intLONGFILE_ERRORFail if a long file name is required in the archive.private intlongFileModeprivate java.io.OutputStreamoutprivate ArArchiveEntryprevEntry
-
Constructor Summary
Constructors Constructor Description ArArchiveOutputStream(java.io.OutputStream pOut)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Calls finish if necessary, and then closes the OutputStreamvoidcloseArchiveEntry()Closes the archive entry, writing any trailer information that may be required.ArchiveEntrycreateArchiveEntry(java.io.File inputFile, java.lang.String entryName)Create an archive entry using the inputFile and entryName provided.ArchiveEntrycreateArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options)Create an archive entry using the inputPath and entryName provided.private longfill(long pOffset, long pNewOffset, char pFill)voidfinish()Finishes the addition of entries to this stream, without closing it.voidputArchiveEntry(ArchiveEntry pEntry)Writes the headers for an archive entry to the output stream.voidsetLongFileMode(int longFileMode)Set the long file mode.voidwrite(byte[] b, int off, int len)private longwrite(java.lang.String data)private voidwriteArchiveHeader()private voidwriteEntryHeader(ArArchiveEntry pEntry)-
Methods inherited from class org.apache.commons.compress.archivers.ArchiveOutputStream
canWriteEntryData, count, count, getBytesWritten, getCount, write
-
-
-
-
Field Detail
-
LONGFILE_ERROR
public static final int LONGFILE_ERROR
Fail if a long file name is required in the archive.- See Also:
- Constant Field Values
-
LONGFILE_BSD
public static final int LONGFILE_BSD
BSD ar extensions are used to store long file names in the archive.- See Also:
- Constant Field Values
-
out
private final java.io.OutputStream out
-
entryOffset
private long entryOffset
-
prevEntry
private ArArchiveEntry prevEntry
-
haveUnclosedEntry
private boolean haveUnclosedEntry
-
longFileMode
private int longFileMode
-
finished
private boolean finished
indicates if this archive is finished
-
-
Method Detail
-
setLongFileMode
public void setLongFileMode(int longFileMode)
Set the long file mode. This can be LONGFILE_ERROR(0) or LONGFILE_BSD(1). This specifies the treatment of long file names (names >= 16). Default is LONGFILE_ERROR.- Parameters:
longFileMode- the mode to use- Since:
- 1.3
-
writeArchiveHeader
private void writeArchiveHeader() throws java.io.IOException- Throws:
java.io.IOException
-
closeArchiveEntry
public void closeArchiveEntry() throws java.io.IOExceptionDescription copied from class:ArchiveOutputStreamCloses the archive entry, writing any trailer information that may be required.- Specified by:
closeArchiveEntryin classArchiveOutputStream- Throws:
java.io.IOException- if an I/O error occurs
-
putArchiveEntry
public void putArchiveEntry(ArchiveEntry pEntry) throws java.io.IOException
Description copied from class:ArchiveOutputStreamWrites the headers for an archive entry to the output stream. The caller must then write the content to the stream and callArchiveOutputStream.closeArchiveEntry()to complete the process.- Specified by:
putArchiveEntryin classArchiveOutputStream- Parameters:
pEntry- describes the entry- Throws:
java.io.IOException- if an I/O error occurs
-
fill
private long fill(long pOffset, long pNewOffset, char pFill) throws java.io.IOException- Throws:
java.io.IOException
-
write
private long write(java.lang.String data) throws java.io.IOException- Throws:
java.io.IOException
-
writeEntryHeader
private void writeEntryHeader(ArArchiveEntry pEntry) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCalls finish if necessary, and then closes the OutputStream- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
createArchiveEntry
public ArchiveEntry createArchiveEntry(java.io.File inputFile, java.lang.String entryName) throws java.io.IOException
Description copied from class:ArchiveOutputStreamCreate an archive entry using the inputFile and entryName provided.- Specified by:
createArchiveEntryin classArchiveOutputStream- Parameters:
inputFile- the file to create the entry fromentryName- name to use for the entry- Returns:
- the ArchiveEntry set up with details from the file
- Throws:
java.io.IOException- if an I/O error occurs
-
createArchiveEntry
public ArchiveEntry createArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options) throws java.io.IOException
Create an archive entry using the inputPath and entryName provided. The default implementation calls simply delegates as:return createArchiveEntry(inputFile.toFile(), entryName);
Subclasses should override this method.- Overrides:
createArchiveEntryin classArchiveOutputStream- Parameters:
inputPath- the file to create the entry fromentryName- name to use for the entryoptions- options indicating how symbolic links are handled.- Returns:
- the ArchiveEntry set up with details from the file
- Throws:
java.io.IOException- if an I/O error occurs- Since:
- 1.21
-
finish
public void finish() throws java.io.IOExceptionDescription copied from class:ArchiveOutputStreamFinishes the addition of entries to this stream, without closing it. Additional data can be written, if the format supports it.- Specified by:
finishin classArchiveOutputStream- Throws:
java.io.IOException- if the user forgets to close the entry.
-
-