bodewig commented on a change in pull request #83: COMPRESS-342 random access
of 7z files
URL: https://github.com/apache/commons-compress/pull/83#discussion_r341814654
##########
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];
Review comment:
Add an extra check for `folderIndex < 0`, which would indicate an empty file
not associated with any stream and so its size *should* be zero. Unfortunately
we've seen archives who look different, so an extra check seems to be necessary.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services