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 void
copyFromClassLoader
(@NotNull ClassLoader loader, @NotNull String name, @NotNull Path target) Copies a file from classloader.static void
copyFromClassLoaderIfNotExists
(@NotNull ClassLoader loader, @NotNull String name, @NotNull Path target) Copies a file from classloader if thetarget
not exists.static void
copyFromJar
(@NotNull Path jarPath, @NotNull String name, @NotNull Path target) Copies a file from jar.static void
copyFromJar
(@NotNull JarFile jar, @NotNull String name, @NotNull Path target) Copies a file from jar.static void
copyFromJarIfNotExists
(@NotNull Path jarPath, @NotNull String name, @NotNull Path target) Copies a file from jar if thetarget
not exists.static void
copyFromJarIfNotExists
(@NotNull JarFile jar, @NotNull String name, @NotNull Path target) Copies a file from jar if thetarget
not exists.static @NotNull InputStream
getInputStreamFromClassLoader
(@NotNull ClassLoader classLoader, @NotNull String name) Gets anInputStream
from theClassLoader
.static @NotNull InputStream
getInputStreamFromJar
(@NotNull JarFile jar, @NotNull String name) Gets anInputStream
from 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
- ifnull
is 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 thetarget
not exists.- Parameters:
loader
- the classloadername
- the filenametarget
- the filepath to save- Throws:
IOException
- if an I/O error occursNullPointerException
- ifnull
is 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
- ifnull
is 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 thetarget
not exists.- Parameters:
jar
- the jar filename
- the filenametarget
- the filepath to save- Throws:
IOException
- if an I/O error occursNullPointerException
- ifnull
is 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
- ifnull
is 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 thetarget
not exists.- Parameters:
jarPath
- the jar filepathname
- the filenametarget
- the filepath to save- Throws:
IOException
- if an I/O error occursNullPointerException
- ifnull
is specified as an argument.
-
getInputStreamFromClassLoader
@NotNull public static @NotNull InputStream getInputStreamFromClassLoader(@NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull String name) Gets anInputStream
from theClassLoader
.- Parameters:
classLoader
- theClassLoader
to get anInputStream
name
- the resource name- Returns:
ClassLoader.getResourceAsStream(String)
- Throws:
IllegalStateException
- if the resource was not foundNullPointerException
- ifnull
is specified as an argument.
-
getInputStreamFromJar
@NotNull public static @NotNull InputStream getInputStreamFromJar(@NotNull @NotNull JarFile jar, @NotNull @NotNull String name) throws IOException Gets anInputStream
from theJarFile
.- Parameters:
jar
- theJarFile
to get anInputStream
name
- the resource name- Returns:
- the
InputStream
fromJarFile.getInputStream(ZipEntry)
- Throws:
IOException
- if an I/O error occursIllegalStateException
- if the resource was not foundNullPointerException
- ifnull
is specified as an argument.
-