Class FileLoader

java.lang.Object
com.deco2800.game.files.FileLoader

public class FileLoader
extends java.lang.Object
Wrapper for reading Java objects from JSON files.

A generic method is provided already, but methods for reading specific classes can be added for more control.

  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  FileLoader.Location  
  • Constructor Summary

    Constructors 
    Constructor Description
    FileLoader()  
  • Method Summary

    Modifier and Type Method Description
    static <T> T readClass​(java.lang.Class<T> type, java.lang.String filename)
    Read generic Java classes from a JSON file.
    static <T> T readClass​(java.lang.Class<T> type, java.lang.String filename, FileLoader.Location location)
    Read generic Java classes from a JSON file.
    static void writeClass​(java.lang.Object object, java.lang.String filename)
    Write generic Java classes to a JSON file.
    static void writeClass​(java.lang.Object object, java.lang.String filename, FileLoader.Location location)
    Write generic Java classes to a JSON file.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • readClass

      public static <T> T readClass​(java.lang.Class<T> type, java.lang.String filename)
      Read generic Java classes from a JSON file. Properties in the JSON file will override class defaults.
      Type Parameters:
      T - Class type to read JSON into
      Parameters:
      type - class type
      filename - file to read from
      Returns:
      instance of class, may be null
    • readClass

      public static <T> T readClass​(java.lang.Class<T> type, java.lang.String filename, FileLoader.Location location)
      Read generic Java classes from a JSON file. Properties in the JSON file will override class defaults.
      Type Parameters:
      T - Class type to read JSON into
      Parameters:
      type - class type
      filename - file to read from
      location - File storage type. See https://github.com/libgdx/libgdx/wiki/File-handling#file-storage-types
      Returns:
      instance of class, may be null
    • writeClass

      public static void writeClass​(java.lang.Object object, java.lang.String filename)
      Write generic Java classes to a JSON file.
      Parameters:
      object - Java object to write.
      filename - File to write to.
    • writeClass

      public static void writeClass​(java.lang.Object object, java.lang.String filename, FileLoader.Location location)
      Write generic Java classes to a JSON file.
      Parameters:
      object - Java object to write.
      filename - File to write to.
      location - File storage type. See https://github.com/libgdx/libgdx/wiki/File-handling#file-storage-types