Tamas Mucs created COMPRESS-596:
-----------------------------------
Summary: 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
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)