Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-596

Mistake in Common Archival Logic code example

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      There is an error on the documentation on page https://commons.apache.org/proper/commons-compress/examples.html  in section "Common Archival Logic "

      Currently the example code looks like this:

      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();
      } 

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            tamas.mucs Tamas Mucs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: