Skip to content

Commit

Permalink
Always close SevenZFile after extraction.
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
simonnagl committed Nov 22, 2019
1 parent ffc1b69 commit b9685ea
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/groovy/eu/emundo/gradle/sevenz/UnSevenZ.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ class UnSevenZ extends DefaultTask {

@TaskAction
void extract(IncrementalTaskInputs inputs) {
SevenZFile sevenZFile = new SevenZFile(sourceFile)
SevenZArchiveEntry entry
while ((entry = sevenZFile.getNextEntry()) != null) {
if (entry.isDirectory()) {
continue
}
File curfile = new File(outputDir, entry.getName())
File parent = curfile.getParentFile()
if (parent != null && !parent.exists()) {
parent.mkdirs()
}
new SevenZFile(sourceFile).withCloseable {sevenZFile ->
SevenZArchiveEntry entry
while ((entry = sevenZFile.getNextEntry()) != null) {
if (entry.isDirectory()) {
continue
}
File curfile = new File(outputDir, entry.getName())
File parent = curfile.getParentFile()
if (parent != null && !parent.exists()) {
parent.mkdirs()
}

int currByte = 0;
new BufferedOutputStream(new FileOutputStream(curfile)).withStream { ostream ->
while( (currByte = sevenZFile.read()) != -1 ) {
ostream.write(currByte);
int currByte = 0;
new BufferedOutputStream(new FileOutputStream(curfile)).withStream { ostream ->
while( (currByte = sevenZFile.read()) != -1 ) {
ostream.write(currByte);
}
}
}
}

}

}

0 comments on commit b9685ea

Please sign in to comment.