public final class Jars
extends java.lang.Object
JarFile and JarEntry.
This class serves to reduce the total amount of code required by the Jar API by providing common or otherwise useful functionality in the form of static methods.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
contains(java.util.jar.JarFile jar,
java.nio.file.Path path)
Returns true if the specified jar file contains an entry matching the path.
|
static xyz.maow.jarvae.Jars.JarEntries |
entries(java.util.jar.JarFile jar)
Wraps the entries of the specified jar file around an iterable class.
|
static java.util.List<java.util.jar.JarEntry> |
entriesList(java.util.jar.JarFile jar)
Creates a new list of jar entries to store the specified jar file's entries.
|
static java.io.File |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.io.File file)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.io.File |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.io.File file,
int bufferSize)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.nio.file.Path |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.nio.file.Path path)
Extracts a jar entry to a file at the specified path with the default buffer size of 1024.
|
static java.nio.file.Path |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.nio.file.Path path,
int bufferSize)
Extracts a jar entry to a file at the specified path with the specified buffer size.
|
static java.io.File |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.lang.String s)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.io.File |
extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.lang.String s,
int bufferSize)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static void |
forEach(java.util.jar.JarFile jar,
java.util.function.Consumer<java.util.jar.JarEntry> consumer)
Iterates over each entry in a jar file, calling a
Consumer on them. |
static java.nio.file.FileSystem |
getJarFileSystem(java.nio.file.Path path)
Returns a
FileSystem representing the filesystem of the Path as a jar file. |
static java.nio.file.FileSystem |
getJarFileSystem(java.nio.file.Path path,
java.util.Map<java.lang.String,java.lang.String> env)
Returns a
FileSystem representing the filesystem of the Path as a jar file. |
static java.util.stream.Stream<java.lang.String> |
lines(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
Returns a
Stream that can be used to read the lines of a jar entry. |
static java.util.jar.JarInputStream |
newInputStream(java.io.File file)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.util.jar.JarInputStream |
newInputStream(java.nio.file.Path path)
Creates a new jar input stream from a path.
|
static java.util.jar.JarInputStream |
newInputStream(java.lang.String... strings)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.util.jar.JarOutputStream |
newOutputStream(java.io.File file)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static java.util.jar.JarOutputStream |
newOutputStream(java.nio.file.Path path)
Creates a new jar output stream from a path.
|
static java.util.jar.JarOutputStream |
newOutputStream(java.lang.String... strings)
Deprecated.
To reduce overall complexity, this method has been deprecated.
|
static byte[] |
readAllBytes(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
Using a jar file, reads the contents of a jar entry as a byte array, using the default buffer size of 1024.
|
static byte[] |
readAllBytes(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
int bufferSize)
Using a jar file, reads the contents of a jar entry as a byte array, using the specified buffer size.
|
static java.util.List<java.lang.String> |
readAllLines(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
Reads all the lines in an entry to a
List<String>. |
public static boolean contains(java.util.jar.JarFile jar,
java.nio.file.Path path)
jar - the specified jar filepath - a path representing a possible entry in the specified jar filepublic static java.nio.file.FileSystem getJarFileSystem(java.nio.file.Path path,
java.util.Map<java.lang.String,java.lang.String> env)
throws java.io.IOException,
java.net.URISyntaxException
FileSystem representing the filesystem of the Path as a jar file.
Instead of constructing a new empty map by hand, use getJarFileSystem(Path).
path - the path of the target jar fileenv - provider-specific configuration properties, should be empty instead of nullFileSystem representing a jar filejava.io.IOException - if an I/O exception has occurredjava.net.URISyntaxException - if the URI was unable to be parsedjava.lang.NullPointerException - if path or env are nullpublic static java.nio.file.FileSystem getJarFileSystem(java.nio.file.Path path)
throws java.io.IOException,
java.net.URISyntaxException
FileSystem representing the filesystem of the Path as a jar file.path - the path of the target jar fileFileSystem representing a jar filejava.io.IOException - if an I/O exception has occurredjava.net.URISyntaxException - if the URI was unable to be parsedjava.lang.NullPointerException - if path is nullpublic static java.util.stream.Stream<java.lang.String> lines(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
throws java.io.IOException
Stream that can be used to read the lines of a jar entry.
As opposed to readAllLines(JarFile, JarEntry), this method is lazily-evaluated.
This means that it is better to use this method on large files instead of the mentioned readAllLines.
jar - the jar file this entry resides inentry - the target jar entry to readStream containing the lines in this jar entryjava.io.IOException - if an I/O exception has occurredpublic static java.util.List<java.lang.String> readAllLines(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
throws java.io.IOException
List<String>.
Should not be used when reading larger files, as it will take a lot of memory due to being eagerly-evaluated.
jar - the jar file this entry resides inentry - the target jar entry to readjava.io.IOException - if an I/O exception has occurredjava.lang.NullPointerException - if jar or entry are nullpublic static byte[] readAllBytes(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
int bufferSize)
throws java.io.IOException
jar - the jar fileentry - the jar entry being read frombufferSize - the size of the buffer used to read from the entrybyte[]java.io.IOException - if an I/O exception has occurredjava.lang.NullPointerException - if jar or entry are nullpublic static byte[] readAllBytes(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry)
throws java.io.IOException
jar - the jar fileentry - the jar entry being read frombyte[]java.io.IOException - if an I/O exception has occurred@Deprecated
public static java.io.File extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.io.File file,
int bufferSize)
throws java.io.IOException
java.io.IOExceptionextract(JarFile, JarEntry, Path, int)@Deprecated
public static java.io.File extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.io.File file)
throws java.io.IOException
java.io.IOExceptionextract(JarFile, JarEntry, Path)@Deprecated
public static java.io.File extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.lang.String s,
int bufferSize)
throws java.io.IOException
java.io.IOExceptionextract(JarFile, JarEntry, Path, int)@Deprecated
public static java.io.File extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.lang.String s)
throws java.io.IOException
java.io.IOExceptionextract(JarFile, JarEntry, Path)public static java.nio.file.Path extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.nio.file.Path path,
int bufferSize)
throws java.io.IOException
jar - a jar fileentry - the jar entry to be extractedpath - the path of the filebufferSize - the size of the buffer being used to read from the entryPath passed to this methodjava.io.IOException - if an I/O exception has occurredpublic static java.nio.file.Path extract(java.util.jar.JarFile jar,
java.util.jar.JarEntry entry,
java.nio.file.Path path)
throws java.io.IOException
jar - a jar fileentry - the jar entry to be extractedpath - the path of the filePath passed to this methodjava.io.IOException - if an I/O exception has occurredpublic static xyz.maow.jarvae.Jars.JarEntries entries(java.util.jar.JarFile jar)
This can be used to iterate over the entries of a jar file using the enhanced for loop (or foreach) syntax.
for (JarEntry entry : Jars.entries(jar)) {
...
}
jar - the specified jar filepublic static java.util.List<java.util.jar.JarEntry> entriesList(java.util.jar.JarFile jar)
jar - the specified jar filejava.lang.NullPointerException - if jar is nullpublic static void forEach(java.util.jar.JarFile jar,
java.util.function.Consumer<java.util.jar.JarEntry> consumer)
Consumer on them.
This method serves as a functional alternative to entries(JarFile).
jar - the specified jar fileconsumer - the action to perform on each entryjava.lang.NullPointerException - if jar or consumer is null@Deprecated
public static java.util.jar.JarInputStream newInputStream(java.lang.String... strings)
throws java.io.IOException
java.io.IOExceptionnewInputStream(Path)@Deprecated
public static java.util.jar.JarInputStream newInputStream(java.io.File file)
throws java.io.IOException
java.io.IOExceptionnewInputStream(Path)public static java.util.jar.JarInputStream newInputStream(java.nio.file.Path path)
throws java.io.IOException
This is purely cosmetic and only serves to reduce clutter.
path - a path representing a jar fileJarInputStream from the specified pathjava.io.IOException - if an I/O exception occurred@Deprecated
public static java.util.jar.JarOutputStream newOutputStream(java.lang.String... strings)
throws java.io.IOException
java.io.IOExceptionnewOutputStream(Path)@Deprecated
public static java.util.jar.JarOutputStream newOutputStream(java.io.File file)
throws java.io.IOException
java.io.IOExceptionnewOutputStream(Path)public static java.util.jar.JarOutputStream newOutputStream(java.nio.file.Path path)
throws java.io.IOException
This is purely cosmetic and only serves to reduce clutter.
path - a path representing a jar fileJarOutputStream from the specified pathjava.io.IOException - if an I/O exception occurred