11/*
2- * Copyright (c) 2015, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2023 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2727
2828import static com .oracle .svm .core .jdk .Resources .RESOURCES_INTERNAL_PATH_SEPARATOR ;
2929
30+ import java .io .File ;
3031import java .io .IOException ;
3132import java .io .InputStream ;
3233import java .lang .reflect .InvocationTargetException ;
@@ -281,12 +282,12 @@ private void processResourceFromModule(Module module, String resourcePath) {
281282 }
282283 }
283284
284- InputStream is = module .getResourceAsStream (resourcePath );
285285 boolean isDirectory = Files .isDirectory (Path .of (resourcePath ));
286286 if (isDirectory ) {
287287 String content = getDirectoryContent (resourcePath , false );
288288 Resources .singleton ().registerDirectoryResource (module , resourcePath , content , false );
289289 } else {
290+ InputStream is = module .getResourceAsStream (resourcePath );
290291 registerResource (module , resourcePath , false , is );
291292 }
292293 } catch (IOException e ) {
@@ -310,13 +311,13 @@ private void processResourceFromClasspath(String resourcePath) {
310311 while (urls .hasMoreElements ()) {
311312 URL url = urls .nextElement ();
312313 try {
313- InputStream is = url .openStream ();
314314 boolean fromJar = url .getProtocol ().equalsIgnoreCase ("jar" );
315315 boolean isDirectory = resourceIsDirectory (url , fromJar , resourcePath );
316316 if (isDirectory ) {
317317 String content = getDirectoryContent (fromJar ? url .toString () : Paths .get (url .toURI ()).toString (), fromJar );
318318 Resources .singleton ().registerDirectoryResource (null , resourcePath , content , fromJar );
319319 } else {
320+ InputStream is = url .openStream ();
320321 registerResource (null , resourcePath , fromJar , is );
321322 }
322323 } catch (IOException e ) {
@@ -343,17 +344,17 @@ private void registerResource(Module module, String resourcePath, boolean fromJa
343344 }
344345
345346 /* Util functions for resource attributes calculations */
346- private String urlToJarPath (URL url ) {
347+ private JarFile urlToJarFile (URL url ) {
347348 try {
348- return ((JarURLConnection ) url .openConnection ()).getJarFileURL (). getFile ();
349+ return ((JarURLConnection ) url .openConnection ()).getJarFile ();
349350 } catch (IOException e ) {
350351 throw new RuntimeException (e );
351352 }
352353 }
353354
354355 private boolean resourceIsDirectory (URL url , boolean fromJar , String resourcePath ) throws IOException , URISyntaxException {
355356 if (fromJar ) {
356- try (JarFile jf = new JarFile ( urlToJarPath ( url ) )) {
357+ try (JarFile jf = urlToJarFile ( url )) {
357358 return jf .getEntry (resourcePath ).isDirectory ();
358359 }
359360 } else {
@@ -364,7 +365,7 @@ private boolean resourceIsDirectory(URL url, boolean fromJar, String resourcePat
364365 private String getDirectoryContent (String path , boolean fromJar ) throws IOException {
365366 Set <String > content = new TreeSet <>();
366367 if (fromJar ) {
367- try (JarFile jf = new JarFile ( urlToJarPath ( URI .create (path ).toURL () ))) {
368+ try (JarFile jf = urlToJarFile ( URI .create (path ).toURL ())) {
368369 String pathSeparator = FileSystems .getDefault ().getSeparator ();
369370 String directoryPath = path .split ("!" )[1 ];
370371
0 commit comments