@@ -57,6 +57,12 @@ public class FileLocator implements InputStreamProvider {
5757 */
5858 protected FileLocalizingListener fileLocalizingListener ;
5959
60+ protected String directory ;
61+
62+ protected String filePath ;
63+
64+ protected ZipCompressionType compressionType ;
65+
6066 /**
6167 * Locates a filesystem inside an external zip compression, the zip filesystem is defined as a {@link ZipFile} object and
6268 * the locatable filesystem is defined as a {@link ZipEntry} object.
@@ -71,9 +77,9 @@ public class FileLocator implements InputStreamProvider {
7177 * @throws IOException if the jar to be located is not found or an interrupted I/O exception has occured
7278 */
7379 public FileLocator (String directory , String filePath , ZipCompressionType compressionType ) throws IOException {
74- ZipFile compression = compressionType . createNewCompressionObject ( directory ) ;
75- ZipEntry nativeLibraryEntry = compression . getEntry ( filePath ) ;
76- this .fileInputStream = compression . getInputStream ( nativeLibraryEntry ) ;
80+ this . directory = directory ;
81+ this . filePath = filePath ;
82+ this .compressionType = compressionType ;
7783 }
7884
7985 /**
@@ -82,14 +88,21 @@ public FileLocator(String directory, String filePath, ZipCompressionType compres
8288 protected FileLocator () {
8389 }
8490
91+ public void initializeLocator () throws IOException {
92+ ZipFile compression = compressionType .createNewCompressionObject (directory );
93+ ZipEntry zipEntry = compression .getEntry (filePath );
94+ validateFileLocalization (zipEntry );
95+ this .fileInputStream = compression .getInputStream (zipEntry );
96+ }
97+
8598 /**
8699 * Validates the file localization process inside the compression.
87100 *
88101 * @throws FileNotFoundException if the localization of the file inside
89102 * the specified compression has failed.
90103 */
91- public void validateFileLocalization () throws FileNotFoundException {
92- if (fileInputStream != null ) {
104+ protected void validateFileLocalization (final ZipEntry zipEntry ) throws FileNotFoundException {
105+ if (zipEntry != null ) {
93106 if (fileLocalizingListener != null ) {
94107 fileLocalizingListener .onFileLocalizationSuccess (this );
95108 }
@@ -111,8 +124,10 @@ public InputStream getFileInputStream() {
111124
112125 @ Override
113126 public void close () throws IOException {
114- fileInputStream .close ();
115- fileInputStream = null ;
127+ if (fileInputStream != null ) {
128+ fileInputStream .close ();
129+ fileInputStream = null ;
130+ }
116131 }
117132
118133 @ Override
0 commit comments