Class ResourceUtils
java.lang.Object
com.github.siroshun09.configapi.core.util.ResourceUtils
A utility class that provides methods to copy files contained in a jar.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyFromClassLoader(@NotNull ClassLoader loader, @NotNull String name, @NotNull Path target) Copies a file from classloader.static voidcopyFromClassLoaderIfNotExists(@NotNull ClassLoader loader, @NotNull String name, @NotNull Path target) Copies a file from classloader if thetargetnot exists.static voidcopyFromJar(@NotNull Path jarPath, @NotNull String name, @NotNull Path target) Copies a file from jar.static voidcopyFromJar(@NotNull JarFile jar, @NotNull String name, @NotNull Path target) Copies a file from jar.static voidcopyFromJarIfNotExists(@NotNull Path jarPath, @NotNull String name, @NotNull Path target) Copies a file from jar if thetargetnot exists.static voidcopyFromJarIfNotExists(@NotNull JarFile jar, @NotNull String name, @NotNull Path target) Copies a file from jar if thetargetnot exists.static @NotNull InputStreamgetInputStreamFromClassLoader(@NotNull ClassLoader classLoader, @NotNull String name) Gets anInputStreamfrom theClassLoader.static @NotNull InputStreamgetInputStreamFromJar(@NotNull JarFile jar, @NotNull String name) Gets anInputStreamfrom theJarFile.
-
Method Details
-
copyFromClassLoader
public static void copyFromClassLoader(@NotNull @NotNull ClassLoader loader, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from classloader.- Parameters:
loader- the classloadername- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.
-
copyFromClassLoaderIfNotExists
public static void copyFromClassLoaderIfNotExists(@NotNull @NotNull ClassLoader loader, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from classloader if thetargetnot exists.- Parameters:
loader- the classloadername- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.- See Also:
-
copyFromJar
public static void copyFromJar(@NotNull @NotNull JarFile jar, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from jar.- Parameters:
jar- the jar filename- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.
-
copyFromJarIfNotExists
public static void copyFromJarIfNotExists(@NotNull @NotNull JarFile jar, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from jar if thetargetnot exists.- Parameters:
jar- the jar filename- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.
-
copyFromJar
public static void copyFromJar(@NotNull @NotNull Path jarPath, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from jar.- Parameters:
jarPath- the jar filepathname- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.
-
copyFromJarIfNotExists
public static void copyFromJarIfNotExists(@NotNull @NotNull Path jarPath, @NotNull @NotNull String name, @NotNull @NotNull Path target) throws IOException Copies a file from jar if thetargetnot exists.- Parameters:
jarPath- the jar filepathname- the filenametarget- the filepath to save- Throws:
IOException- if an I/O error occursNullPointerException- ifnullis specified as an argument.
-
getInputStreamFromClassLoader
@NotNull public static @NotNull InputStream getInputStreamFromClassLoader(@NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull String name) Gets anInputStreamfrom theClassLoader.- Parameters:
classLoader- theClassLoaderto get anInputStreamname- the resource name- Returns:
ClassLoader.getResourceAsStream(String)- Throws:
IllegalStateException- if the resource was not foundNullPointerException- ifnullis specified as an argument.
-
getInputStreamFromJar
@NotNull public static @NotNull InputStream getInputStreamFromJar(@NotNull @NotNull JarFile jar, @NotNull @NotNull String name) throws IOException Gets anInputStreamfrom theJarFile.- Parameters:
jar- theJarFileto get anInputStreamname- the resource name- Returns:
- the
InputStreamfromJarFile.getInputStream(ZipEntry) - Throws:
IOException- if an I/O error occursIllegalStateException- if the resource was not foundNullPointerException- ifnullis specified as an argument.
-