[ 
https://issues.apache.org/jira/browse/COMPRESS-342?focusedWorklogId=340001&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-340001
 ]

ASF GitHub Bot logged work on COMPRESS-342:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Nov/19 15:50
            Start Date: 07/Nov/19 15:50
    Worklog Time Spent: 10m 
      Work Description: bodewig commented on pull request #83: COMPRESS-342 
random access of 7z files
URL: https://github.com/apache/commons-compress/pull/83#discussion_r341814948
 
 

 ##########
 File path: 
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
 ##########
 @@ -1208,6 +1208,42 @@ private InputStream getCurrentStream() throws 
IOException {
         return deferredBlockStreams.get(0);
     }
 
+    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]) {
+                entryIndex = i;
+            }
+        }
+        if(entryIndex < 0) {
+            throw new IllegalArgumentException("Can not find " + 
entry.getName() + " in " + this.fileName);
+        }
+
+        // return empty stream for empty files
+        if(entry.getSize() == 0) {
+            return new ByteArrayInputStream(new byte[0]);
+        }
+
+        final int folderIndex = archive.streamMap.fileFolderIndex[entryIndex];
+        final Folder folder = archive.folders[folderIndex];
+        final int firstPackStreamIndex = 
archive.streamMap.folderFirstPackStreamIndex[folderIndex];
+        final long folderOffset = SIGNATURE_HEADER_SIZE + archive.packPos +
+                archive.streamMap.packStreamOffsets[firstPackStreamIndex];
+        InputStream folderInputStream = buildDecoderStack(folder, 
folderOffset, firstPackStreamIndex, entry);
+
+        final int firstFileInFolderIndex = 
archive.streamMap.folderFirstFileIndex[folderIndex];
+        if(firstFileInFolderIndex < entryIndex) {
+            long skipSize = 0;
+            for(int i = firstFileInFolderIndex; i < entryIndex;i++) {
+                skipSize += archive.files[i].getSize();
+            }
+            InputStream inputStreamToSkip = new 
BoundedInputStream(folderInputStream, skipSize);
+            IOUtils.skip(inputStreamToSkip, Long.MAX_VALUE);
+        }
+
+        return new BoundedInputStream(folderInputStream, entry.getSize());
 
 Review comment:
   this lack the checksum verification `buildDecodingStream` would add towards 
the end of the method.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 340001)
    Time Spent: 2h 40m  (was: 2.5h)

> random access of 7z files
> -------------------------
>
>                 Key: COMPRESS-342
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-342
>             Project: Commons Compress
>          Issue Type: Sub-task
>          Components: Archivers
>            Reporter: Stefan Bodewig
>            Priority: Major
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to