Class Jar

java.lang.Object
net.md_5.specialsource.Jar
All Implemented Interfaces:
Closeable, AutoCloseable

public class Jar extends Object implements Closeable
This class wraps one or more JarFiles enabling quick access to the jar's main class, as well as the ability to get the InputStream of a class file, and speedy lookups to see if the jar contains the specified class.
  • Constructor Details

    • Jar

      public Jar()
  • Method Details

    • containsClass

      public boolean containsClass(String clazz)
      Check if this jar contains the given class. Takes the internal name of a class (/).
      Parameters:
      clazz -
      Returns:
    • containsResource

      public boolean containsResource(String name)
      Check if this jar contains the given resource.
      Parameters:
      name - The name of the resource
      Returns:
      true Whether a resource with the given name exists
    • getResource

      public InputStream getResource(String name) throws IOException
      Get the stream for a file in this jar.
      Parameters:
      name -
      Returns:
      Throws:
      IOException
    • getEntry

      public Pair2<ZipEntry,InputStream> getEntry(String name) throws IOException
      Get the stream for a file in this jar.
      Parameters:
      name -
      Returns:
      Throws:
      IOException
    • getClass

      public InputStream getClass(String clazz) throws IOException
      Takes the internal name of a class (/).
      Parameters:
      clazz -
      Returns:
      Throws:
      IOException
    • getNode

      public org.objectweb.asm.tree.ClassNode getNode(String clazz)
      Get the ClassNode object corresponding to this class. Takes the internal name of a class (/)
      Parameters:
      clazz -
      Returns:
    • getEntryNames

      public Set<String> getEntryNames()
      Get all file names in the jar, (archive order is preserved).
      Returns:
    • init

      public static Jar init(File file) throws IOException
      Read a new jar instance from the given file.
      Parameters:
      file -
      Returns:
      Throws:
      IOException
    • init

      public static Jar init(List<File> files) throws IOException
      Read a new jar instance from the given list of files.
      Parameters:
      files -
      Returns:
      Throws:
      IOException
    • close

      public void close() throws IOException
      Closes all jar files in this Jar
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error has occurred
      See Also: