Class JARResources

java.lang.Object
org.sm.smtools.application.util.JARResources

public final class JARResources
extends java.lang.Object
The JARResources class provides access to JAR and ZIP files.

All the system resources are to be loaded in the static field fSystemResources.

Note that this class cannot be subclassed!

Version:
15/03/2020
Author:
Sven Maerivoet
  • Field Summary

    Fields
    Modifier and Type Field Description
    static JARResources fSystemResources
    Access point to the system resources.
  • Constructor Summary

    Constructors
    Constructor Description
    JARResources​(java.lang.String jarFilename)
    Constructs a JARResources object and loads all resources from it into memory.
  • Method Summary

    Modifier and Type Method Description
    static void checkSystemInitialisation()
    Checks if the system resources are initialised.
    java.awt.image.BufferedImage getBufferedImage​(java.lang.String name)
    Retrieves a resource as a BufferedImage from the archive.
    java.awt.Image getImage​(java.lang.String name)
    Retrieves a resource as an Image from the archive.
    java.io.InputStream getInputStream​(java.lang.String name)
    Retrieves a resource as an InputStream from the archive.
    byte[] getRawResource​(java.lang.String name)
    Retrieves a raw resource from the archive.
    java.lang.StringBuilder getText​(java.lang.String name)
    Retrieves a resource as a StringBuilder from the archive.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fSystemResources

      public static JARResources fSystemResources
      Access point to the system resources.
  • Constructor Details

    • JARResources

      public JARResources​(java.lang.String jarFilename) throws java.io.FileNotFoundException, FileReadException
      Constructs a JARResources object and loads all resources from it into memory.
      Parameters:
      jarFilename - the filename of the JAR or ZIP file containing the resources
      Throws:
      java.io.FileNotFoundException - if the archive file is not found
      FileReadException - if an error occurred during loading resources from the archive file
  • Method Details

    • checkSystemInitialisation

      public static void checkSystemInitialisation()
      Checks if the system resources are initialised. The running application is aborted if this is not the case.
    • getRawResource

      public byte[] getRawResource​(java.lang.String name) throws java.io.FileNotFoundException
      Retrieves a raw resource from the archive.
      Parameters:
      name - the (file)name of the resource to retrieve from the archive
      Returns:
      a byte array representing the resource
      Throws:
      java.io.FileNotFoundException - if the resource was not found
    • getInputStream

      public java.io.InputStream getInputStream​(java.lang.String name) throws java.io.FileNotFoundException
      Retrieves a resource as an InputStream from the archive.
      Parameters:
      name - the (file)name of the resource to retrieve from the archive
      Returns:
      an InputStream representing the resource
      Throws:
      java.io.FileNotFoundException - if the resource was not found
      See Also:
      getRawResource(String name)
    • getText

      public java.lang.StringBuilder getText​(java.lang.String name) throws java.io.FileNotFoundException
      Retrieves a resource as a StringBuilder from the archive.
      Parameters:
      name - the (file)name of the resource to retrieve from the archive
      Returns:
      a StringBuilder representing the resource
      Throws:
      java.io.FileNotFoundException - if the resource was not found
      See Also:
      getRawResource(String name)
    • getImage

      public java.awt.Image getImage​(java.lang.String name) throws java.io.FileNotFoundException
      Retrieves a resource as an Image from the archive.
      Parameters:
      name - the (file)name of the resource to retrieve from the archive
      Returns:
      an Image representing the resource
      Throws:
      java.io.FileNotFoundException - if the resource was not found
      See Also:
      getRawResource(String name)
    • getBufferedImage

      public java.awt.image.BufferedImage getBufferedImage​(java.lang.String name) throws java.io.FileNotFoundException
      Retrieves a resource as a BufferedImage from the archive.
      Parameters:
      name - the (file)name of the resource to retrieve from the archive
      Returns:
      an Image representing the resource
      Throws:
      java.io.FileNotFoundException - if the resource was not found
      See Also:
      getRawResource(String name)