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

Peter Lee commented on COMPRESS-596:
------------------------------------

Hi [~tamas.mucs] 

Thank you for your reporting.

 

No dought the "out" is not defined here. IMO it should be "o" instead of "out". 

Even through the "finish()" is called within "close()", we always explicit call 
the "finish()". We did this in our tests, and I want to make it be consistent 
here.

And I think "o" is reachable here. :)

> Mistake in Common Archival Logic code example
> ---------------------------------------------
>
>                 Key: COMPRESS-596
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-596
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: Tamas Mucs
>            Priority: Minor
>              Labels: compress, docuentation
>
> There is an error on the documentation on page 
> [https://commons.apache.org/proper/commons-compress/examples.html|https://commons.apache.org/proper/commons-compress/examples.html.]
>   in section "Common Archival Logic "
> Currently the example code looks like this:
> {code:java}
> Collection<File> filesToArchive = ...
> try (ArchiveOutputStream o = ... create the stream for your format ...) {
>     for (File f : filesToArchive) {
>         // maybe skip directories for formats like AR that don't store 
> directories
>         ArchiveEntry entry = o.createArchiveEntry(f, entryName(f));
>         // potentially add more flags to entry
>         o.putArchiveEntry(entry);
>         if (f.isFile()) {
>             try (InputStream i = Files.newInputStream(f.toPath())) {
>                 IOUtils.copy(i, o);
>             }
>         }
>         o.closeArchiveEntry();
>     }
>     out.finish();
> } {code}
> The variable "out" is not defined anywhere. Supposedly it is the variable "o" 
> of type ArchiveOutputStream. However it might be redundant to call "finish()" 
> since try-with-resources will implicitly call it via the close() method. Also 
> "o" is not reachable in that context.
>  
> Proposed solution: remove "out".



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to