[ 
https://issues.apache.org/jira/browse/COMPRESS-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12698997#action_12698997
 ] 

Sebb commented on COMPRESS-64:
------------------------------

AIUI, the finish() method is used to ensure that any required trailers etc are 
written to the output stream, i.e. may add data to the stream.
This is different from flush() which ensures that the output stream is written 
to disk (etc.), but does not add any data to the output stream.

AR - no finish() method

CPIO - calls closeArchiveEntry() if necessary and writes the trailer record

TAR - writes the trailer

ZIP/JAR - calls closeArchiveEntry() if necessary and writes the CFH and CD end.

This is inconsistent - TAR does not call closeArchiveEntry(), though this may 
be needed.

Seems to me that the user should be required to always call closeArchiveEntry() 
once for each putArchiveEntry(), i.e. finish() should only do whatever 
processing is needed at the end of an archive.  The finish() method should 
throw an Exception if the user forgets to close the entry, rather than silently 
tidying up for the user.

The normal sequence of calls is:
+ create AOS class
+ write SFX header (optional, Zip only)
+ repeat as needed:
- - putArchiveEntry()
- - write() entry data
- - closeArchiveEntry()
+ finish()
+ write additional data if format supports it (optional)
+ close()

This could be enforced by the ArchiveOutputStream class

> Are the public finish() methods ArchiveOutputStream implementations necessary 
> and safe?
> ---------------------------------------------------------------------------------------
>
>                 Key: COMPRESS-64
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-64
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: Sebb
>
> Some of the ArchiveOutputStream implementations have public finish() methods. 
> These are currently only called from the close() methods.
> Seems to me that there is no need to allow the finish() methods to be called 
> externally, and the user can corrupt the output if they do.
> Surely the close() method is all that is needed?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to