Skip to content

Commit

Permalink
Return the extracted files
Browse files Browse the repository at this point in the history
  • Loading branch information
awaters1 committed May 29, 2017
1 parent a6f7cac commit 28be41d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<packaging>jar</packaging>
<version>0.8-SNAPSHOT</version>
<version>0.9-SNAPSHOT</version>
<name>Java UnRar</name>
<description>rar decompression library in plain java</description>
<url>https://github.com/junrar/junrar</url>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/github/junrar/extract/ExtractArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;

Expand All @@ -25,7 +27,8 @@ public void setLogger(Log logger) {
this.logger = logger;
}

public void extractArchive(File archive, File destination) {
public List<File> extractArchive(File archive, File destination) {
List<File> extractedFiles = new ArrayList<File>();
Archive arch = null;
try {
arch = new Archive(archive);
Expand All @@ -37,7 +40,7 @@ public void extractArchive(File archive, File destination) {
if (arch != null) {
if (arch.isEncrypted()) {
logWarn("archive is encrypted cannot extract");
return;
return extractedFiles;
}
try{
FileHeader fh = null;
Expand All @@ -60,6 +63,7 @@ public void extractArchive(File archive, File destination) {
OutputStream stream = new FileOutputStream(f);
arch.extractFile(fh, stream);
stream.close();
extractedFiles.add(f);
}
} catch (IOException e) {
logError(e, "error extracting the file");
Expand All @@ -75,6 +79,7 @@ public void extractArchive(File archive, File destination) {
}
}
}
return extractedFiles;
}

private void logWarn(String warning) {
Expand Down

0 comments on commit 28be41d

Please sign in to comment.