Skip to content

Commit 2203499

Browse files
committed
FileExtractor#initialize(int): sanity-check the stream provider handler for other routines - apply the close() routine on failure
1 parent 3973871 commit 2203499

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

snaploader/src/main/java/electrostatic4j/snaploader/filesystem/FileExtractor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ protected FileExtractor() {
8686
}
8787

8888
@Override
89-
public void initialize(int size) {
89+
public void initialize(int size) throws Exception {
90+
// 1) sanity-check for double initializing
91+
// 2) sanity-check for pre-initialization using other routines
92+
if (this.fileOutputStream != null) {
93+
return;
94+
}
9095
try {
9196
if (size > 0) {
9297
this.fileOutputStream = new BufferedOutputStream(
@@ -98,7 +103,8 @@ public void initialize(int size) {
98103
this.fileOutputStream = new FileOutputStream(destination);
99104
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "initialize(int)",
100105
"File extractor initialized with hash key #" + getHashKey());
101-
} catch (FileNotFoundException e) {
106+
} catch (Exception e) {
107+
close();
102108
throw new FilesystemResourceInitializationException(
103109
"Failed to initialize the file extractor handler #" + getHashKey(), e);
104110
}

0 commit comments

Comments
 (0)