Package org.sm.smtools.application.util
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 aJARResources
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 aBufferedImage
from the archive.java.awt.Image
getImage(java.lang.String name)
Retrieves a resource as anImage
from the archive.java.io.InputStream
getInputStream(java.lang.String name)
Retrieves a resource as anInputStream
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 aStringBuilder
from the archive.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
fSystemResources
Access point to the system resources.
-
-
Constructor Details
-
JARResources
public JARResources(java.lang.String jarFilename) throws java.io.FileNotFoundException, FileReadExceptionConstructs aJARResources
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 foundFileReadException
- 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.FileNotFoundExceptionRetrieves 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.FileNotFoundExceptionRetrieves a resource as anInputStream
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.FileNotFoundExceptionRetrieves a resource as aStringBuilder
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.FileNotFoundExceptionRetrieves a resource as anImage
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.FileNotFoundExceptionRetrieves a resource as aBufferedImage
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)
-