Package pi.resources

Class ResourceLoader

java.lang.Object
pi.resources.ResourceLoader

public final class ResourceLoader extends Object
Lädt Dateien aus der JAR oder dem aktuellen Arbeitsverzeichnis.
Author:
Niklas Keller
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String file)
    Gets the specified file as InputStream from either a resource folder or the file system.
    get(URL file)
    Gets the specified file as InputStream from either a resource folder or the file system.
    static byte[]
    load(String filename)
     
    static File
    loadAsFile(String filename)
     
    loadAsStream(String filename)
     
    static URL
    Ermittelt die URL zu einer angegebenen Ressource oder Datei.
    static String
    read(String file)
    Reads the specified file as String from either a resource folder or the file system.
    Since no Charset is specified with this overload, the implementation uses UTF-8 by default.
    static String
    read(String file, Charset charset)
    Reads the specified file as String from either a resource folder or the file system.
    static String
    read(URL file)
    Reads the specified file as String from either a resource folder or the file system.
    Since no Charset is specified with this overload, the implementation uses UTF-8 by default.
    static String
    read(URL file, Charset charset)
    Reads the specified file as String from either a resource folder or the file system.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • load

      public static byte[] load(String filename) throws IOException
      Throws:
      IOException
    • loadAsStream

      public static InputStream loadAsStream(String filename) throws IOException
      Throws:
      IOException
    • loadAsFile

      public static File loadAsFile(String filename)
    • get

      public static InputStream get(String file)
      Gets the specified file as InputStream from either a resource folder or the file system.
      Parameters:
      file - The path to the file.
      Returns:
      The contents of the specified file as InputStream.
      See Also:
    • get

      public static InputStream get(URL file)
      Gets the specified file as InputStream from either a resource folder or the file system.
      Parameters:
      file - The path to the file.
      Returns:
      The contents of the specified file as InputStream.
      See Also:
    • read

      public static String read(String file)
      Reads the specified file as String from either a resource folder or the file system.
      Since no Charset is specified with this overload, the implementation uses UTF-8 by default.
      Parameters:
      file - The path to the file.
      Returns:
      The contents of the specified file as String
    • read

      public static String read(String file, Charset charset)
      Reads the specified file as String from either a resource folder or the file system.
      Parameters:
      file - The path to the file.
      charset - The charset that is used to read the String from the file.
      Returns:
      The contents of the specified file as String
    • read

      public static String read(URL file)
      Reads the specified file as String from either a resource folder or the file system.
      Since no Charset is specified with this overload, the implementation uses UTF-8 by default.
      Parameters:
      file - The path to the file.
      Returns:
      The contents of the specified file as String
    • read

      public static String read(URL file, Charset charset)
      Reads the specified file as String from either a resource folder or the file system.
      Parameters:
      file - The path to the file.
      charset - The charset that is used to read the String from the file.
      Returns:
      The contents of the specified file as String
    • location

      @Getter public static URL location(String name)
      Ermittelt die URL zu einer angegebenen Ressource oder Datei.

      Zuerst wird versucht, die Ressource über den System-Klassenlader zu finden. Falls dies nicht gelingt, wird der übergebene Name als URL interpretiert. Ist auch das nicht möglich, wird der Name als Dateipfad behandelt und in eine URL umgewandelt.

      Parameters:
      name - Name der Ressource, URL oder Dateipfad
      Returns:
      die gefundene oder erzeugte URL
      Throws:
      ResourceLoadException - wenn der angegebene Wert weder als Ressource, noch als URL oder gültiger Dateipfad verarbeitet werden kann