diff --git a/vertigo-core/src/main/java/io/vertigo/core/util/FileUtil.java b/vertigo-core/src/main/java/io/vertigo/core/util/FileUtil.java index 46eda0250..f5638f9de 100644 --- a/vertigo-core/src/main/java/io/vertigo/core/util/FileUtil.java +++ b/vertigo-core/src/main/java/io/vertigo/core/util/FileUtil.java @@ -23,12 +23,15 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Pattern; import io.vertigo.core.lang.Assertion; @@ -65,16 +68,26 @@ public static String read(final URL url) { Assertion.check().isNotNull(url); //--- try { - final Path path = Paths.get(url.toURI()); - final List lines = Files.readAllLines(path, StandardCharsets.UTF_8); - return String.join("\r\n", lines); + final var uri = url.toURI(); + if ("jar".equalsIgnoreCase(uri.getScheme())) { + try (final FileSystem fs = FileSystems.newFileSystem(url.toURI(), Map.of())) { // need to "open" the jar for Paths.get to work + return doRead(Paths.get(uri)); + } + } + return doRead(Paths.get(uri)); } catch (final IOException | URISyntaxException e) { throw WrappedException.wrap(e, "Error when reading file : '{0}'", url); } } + private static String doRead(final Path path) throws IOException { + final List lines = Files.readAllLines(path, StandardCharsets.UTF_8); + return String.join("\r\n", lines); + } + /** * Copie le contenu d'un flux d'entrée vers un fichier de sortie. + * * @param in flux d'entrée * @param file fichier de sortie * @throws IOException Erreur d'entrée/sortie @@ -88,6 +101,7 @@ public static void copy(final InputStream in, final File file) throws IOExceptio *

* This method returns the textual part of the filename after the last dot. * There must be no directory separator after the dot. + * *

 	 * foo.txt      --> "txt"
 	 * a/b/c.jpg    --> "jpg"
@@ -96,8 +110,8 @@ public static void copy(final InputStream in, final File file) throws IOExceptio
 	 * 
*

* The output will be the same irrespective of the machine that the code is running on. - * @param fileName Nom du fichier * + * @param fileName Nom du fichier * @return the extension of the file or an empty string if none exists. * (author Apache Commons IO 1.1) */ @@ -125,6 +139,7 @@ public static String getFileExtension(final String fileName) { /** * Replace "user.home" "user.dir" and "java.io.tmpdir" by system value. + * * @param path PAth to translate * @return translated path */ @@ -137,6 +152,7 @@ public static String translatePath(final String path) { /** * Check a filePath send by a user. + * * @param userPath Path to check */ public static void checkUserPath(final String userPath) { @@ -147,6 +163,7 @@ public static void checkUserPath(final String userPath) { /** * Check a filename send by a user. + * * @param userFileName FileName to check */ public static void checkUserFileName(final String userFileName) {