This is an automated email from the ASF dual-hosted git repository. bodewig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 228e73995ea16cb247e5549fed727edfc3a28dce Author: Stefan Bodewig <[email protected]> AuthorDate: Thu Nov 7 17:18:14 2019 +0100 COMPRESS-342 record changes - see #83 --- src/changes/changes.xml | 4 ++++ .../commons/compress/archivers/sevenz/SevenZFile.java | 19 ++++++++++++++++--- src/site/xdoc/examples.xml | 10 ++++++++++ src/site/xdoc/index.xml | 13 +++---------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index abf85e6..ec4b18a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -70,6 +70,10 @@ The <action> type attribute can be add,update,fix,remove. SevenZFile can now revover from a certain corruption that seems to happen occasinally when split archives are created. </action> + <action issue="COMPRESS-342" type="update" date="2019-11-07" + due-to="Peter Alfred Lee"> + Added random access support to SevenZFile. + </action> </release> <release version="1.19" date="2019-08-27" description="Release 1.19 diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index b73cf5c..0e7f0ec 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -1320,15 +1320,28 @@ public class SevenZFile implements Closeable { return deferredBlockStreams.get(0); } + /** + * Returns an InputStream for reading the contents of the given entry. + * + * <p>For archives using solid compression randomly accessing + * entries will be significantly slower than reading the archive + * sequentiallly.</p> + * + * @param entry the entry to get the stream for. + * @return a stream to read the entry from. + * @throws IOException if unable to create an input stream from the zipentry + * @since Compress 1.20 + */ public InputStream getInputStream(SevenZArchiveEntry entry) throws IOException { int entryIndex = -1; - for(int i = 0; i < this.archive.files.length;i++) { - if(entry == this.archive.files[i]) { + for (int i = 0; i < this.archive.files.length;i++) { + if (entry == this.archive.files[i]) { entryIndex = i; + break; } } - if(entryIndex < 0) { + if (entryIndex < 0) { throw new IllegalArgumentException("Can not find " + entry.getName() + " in " + this.fileName); } diff --git a/src/site/xdoc/examples.xml b/src/site/xdoc/examples.xml index 488bbb5..957294e 100644 --- a/src/site/xdoc/examples.xml +++ b/src/site/xdoc/examples.xml @@ -420,6 +420,16 @@ LOOP UNTIL entry.getSize() HAS BEEN READ { } ]]></source> + <h4><a name="Random-Access to 7z Archives"></a>Random-Access to 7z Archives</h4> + + <p>Prior to Compress 1.20 7z archives could only be read + sequentially. The + <code>getInputStream(SevenZArchiveEntry)</code> method + introduced with Compress 1.20 now provides random access but + at least when the archive uses solid compression random access + will likely be significantly slower than sequential + access.</p> + </subsection> <subsection name="ar"> diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 18709b4..8b57f03 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -58,17 +58,10 @@ of changes see the <a href="changes-report.html">Changes Report</a>.</p> - <subsection name="What's new in 1.19?"> + <subsection name="What's new in 1.20?"> <ul> - <li><code>ParallelScatterZipCreator</code> now writes - entries in the same order they have been added to the - archive.</li> - <li><code>ZipArchiveInputStream</code> and - <code>ZipFile</code> are more forgiving when parsing - extra fields by default now.</li> - <li><code>TarArchiveInputStream</code> has a new lenient - mode that may allow it to read certain broken - archives.</li> + <li><code>SevenZFile</code> now supports random + access.</li> </ul> </subsection> </section>
