Skip to content

Commit 3973871

Browse files
committed
FileLocator#initialize(int): sanity-check the stream provider handler for other routines
1 parent 91fbefc commit 3973871

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ protected FileLocator() {
9292

9393

9494
@Override
95-
public void initialize(int size) {
95+
public void initialize(int size) throws IOException {
96+
// 1) sanity-check for double initializing
97+
// 2) sanity-check for pre-initialization using other routines
98+
// (e.g., classpath resources stream).
99+
if (this.fileInputStream != null) {
100+
return;
101+
}
96102
try {
97103
final ZipFile compression = compressionType.createNewCompressionObject(directory);
98104
final ZipEntry zipEntry = compression.getEntry(filePath);
@@ -106,7 +112,8 @@ public void initialize(int size) {
106112
this.fileInputStream = compression.getInputStream(zipEntry);
107113
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "initialize(int)",
108114
"File locator initialized with hash key #" + getHashKey());
109-
} catch (IOException e) {
115+
} catch (Exception e) {
116+
close();
110117
throw new FilesystemResourceInitializationException(
111118
"Failed to initialize the file locator handler #" + getHashKey(), e);
112119
}

0 commit comments

Comments
 (0)