Top Description Fields Constructors Methods
org.apache.commons.compress.archivers

public abstract Class ArchiveOutputStream<E extends org.apache.commons.compress.archivers.ArchiveEntry>

extends OutputStream
Class Inheritance
Known Direct Subclasses
org.apache.commons.compress.archivers.ar.ArArchiveOutputStream, org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream, org.apache.commons.compress.archivers.tar.TarArchiveOutputStream, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
Type Parameters
<E>
The type of ArchiveEntry consumed.
Imports
java.io.File, .IOException, .OutputStream, java.nio.file.LinkOption, .Path

Archive output stream implementations are expected to override the write(byte[], int, int) method to improve performance. They should also override close() to ensure that any necessary trailers are added.

The normal sequence of calls when working with ArchiveOutputStreams is:

Field Summary

Modifier and TypeField and Description
pack-priv static final int
private long
bytesWritten

Holds the number of bytes written to this stream.

private final byte[]
oneByte

Temporary buffer used for the write(int) method.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

This implementation always returns true.
canWriteEntryData
(final ArchiveEntry
the entry to test
archiveEntry
)

Whether this stream is able to write the given entry.

public abstract void
closeArchiveEntry()

Closes the archive entry, writing any trailer information that may be required.

protected void
count(final int
the number of bytes written
written
)

Increments the counter of already written bytes.

protected void
count(final long
the number of bytes written
written
)

Increments the counter of already written bytes.

public abstract E

Returns:

the ArchiveEntry set up with details from the file
createArchiveEntry
(File
the file to create the entry from
inputFile
,
String
name to use for the entry
entryName
)

Creates an archive entry using the inputFile and entryName provided.

public E

Returns:

the ArchiveEntry set up with details from the file
createArchiveEntry
(final Path
the file to create the entry from
inputPath
,
final String
name to use for the entry
entryName
,
final LinkOption...
options indicating how symbolic links are handled.
options
)

Creates an archive entry using the inputPath and entryName provided.

public abstract void
finish()

Finishes the addition of entries to this stream, without closing it.

public long

Returns:

the number of written bytes
getBytesWritten
()

Gets the current number of bytes written to this stream.

public int

Returns:

the number of written bytes
getCount
()

Deprecated this method may yield wrong results for large archives, use #getBytesWritten instead
Gets the current number of bytes written to this stream.
public abstract void
putArchiveEntry(E
describes the entry
entry
)

Writes the headers for an archive entry to the output stream.

public void
write(final int
The byte to be written.
b
)

Implements abstract java.io.OutputStream.write.

Writes a byte to the current archive entry.
Inherited from java.io.OutputStream:
closeflushnullOutputStreamwritewrite

Field Detail

BYTE_MASKback to summary
pack-priv static final int BYTE_MASK
bytesWrittenback to summary
private long bytesWritten

Holds the number of bytes written to this stream.

oneByteback to summary
private final byte[] oneByte

Temporary buffer used for the write(int) method.

Constructor Detail

ArchiveOutputStreamback to summary
public ArchiveOutputStream()

Method Detail

canWriteEntryDataback to summary
public boolean canWriteEntryData(final ArchiveEntry archiveEntry)

Whether this stream is able to write the given entry.

Some archive formats support variants or details that are not supported (yet).

Parameters
archiveEntry:ArchiveEntry

the entry to test

Returns:boolean

This implementation always returns true.

Since
1.1
closeArchiveEntryback to summary
public abstract void closeArchiveEntry() throws IOException

Closes the archive entry, writing any trailer information that may be required.

Exceptions
IOException:
if an I/O error occurs
countback to summary
protected void count(final int written)

Increments the counter of already written bytes. Doesn't increment if EOF has been hit (written == -1).

Parameters
written:int

the number of bytes written

countback to summary
protected void count(final long written)

Increments the counter of already written bytes. Doesn't increment if EOF has been hit (written == -1).

Parameters
written:long

the number of bytes written

Since
1.1
createArchiveEntryback to summary
public abstract E createArchiveEntry(File inputFile, String entryName) throws IOException

Creates an archive entry using the inputFile and entryName provided.

Parameters
inputFile:File

the file to create the entry from

entryName:String

name to use for the entry

Returns:E

the ArchiveEntry set up with details from the file

Exceptions
IOException:
if an I/O error occurs
createArchiveEntryback to summary
public E createArchiveEntry(final Path inputPath, final String entryName, final LinkOption... options) throws IOException

Creates 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.

Parameters
inputPath:Path

the file to create the entry from

entryName:String

name to use for the entry

options:LinkOption[]

options indicating how symbolic links are handled.

Returns:E

the ArchiveEntry set up with details from the file

Exceptions
IOException:
if an I/O error occurs
Since
1.21
finishback to summary
public abstract void finish() throws IOException

Finishes the addition of entries to this stream, without closing it. Additional data can be written, if the format supports it.

Exceptions
IOException:
if the user forgets to close the entry.
getBytesWrittenback to summary
public long getBytesWritten()

Gets the current number of bytes written to this stream.

Returns:long

the number of written bytes

Since
1.1
getCountback to summary
public int getCount()

Deprecated

this method may yield wrong results for large archives, use #getBytesWritten instead

Gets the current number of bytes written to this stream.

Returns:int

the number of written bytes

Annotations
@Deprecated
putArchiveEntryback to summary
public abstract void putArchiveEntry(E entry) throws IOException

Writes the headers for an archive entry to the output stream. The caller must then write the content to the stream and call closeArchiveEntry() to complete the process.

Parameters
entry:E

describes the entry

Exceptions
IOException:
if an I/O error occurs
writeback to summary
public void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Writes a byte to the current archive entry.

This method simply calls write( byte[], 0, 1 ).

MUST be overridden if the write(byte[], int, int) method is not overridden; may be overridden otherwise.

Parameters
b:int

The byte to be written.

Annotations
@Override
Exceptions
IOException:
on error