java.lang.Object
net.buildtheearth.terraminusminus.util.http.Disk

public final class Disk extends Object
Handles disk I/O operations for Http.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Path
    cacheFileFor(@NonNull String url)
    Gets the file path which stores the cached data for the given url.
    static Path
    configFile(@NonNull String name)
    Gets the path to an additional configuration file with the given name.
    static CompletableFuture<io.netty.buffer.ByteBuf>
    read(@NonNull Path file)
    Asynchronously reads a file's contents into a ByteBuf.
    static void
    setCacheRoot(@NonNull File cacheDir)
    Set the directory where Terra-- should store its HTTP cache files.
    static void
    setConfigRoot(@NonNull File configDir)
    Set the directory where Terra-- should look for configuration files like osm.json5 or heights.json5.
    static void
    write(@NonNull Path file, @NonNull io.netty.buffer.ByteBuf data)
    Asynchronously writes a file's contents, replacing the existing file if it already exists.

    Methods inherited from class java.lang.Object

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

    • setCacheRoot

      public static void setCacheRoot(@NonNull @NonNull File cacheDir) throws IllegalStateException
      Set the directory where Terra-- should store its HTTP cache files.
      The cache root can only be set once. As a consequence, calling this methode multiple times will result in an IllegalStateException being thrown.
      If this is not manually called before using any method that makes use of the cache, the cache root will be automatically set to $CWD/terraminusminus/cache, and further attempts to call this method will result in an IllegalStateException being thrown.
      This method and its implementation are unique to Terra--, as Terra++ is hardcoded to use .minecraft/terraplusplus/cache.
      Parameters:
      cacheDir - the root of the cache
      Throws:
      IllegalStateException
    • setConfigRoot

      public static void setConfigRoot(@NonNull @NonNull File configDir)
      Set the directory where Terra-- should look for configuration files like osm.json5 or heights.json5.
      The config root can only be set once. As a consequence, calling this methode multiple times will result in an IllegalStateException being thrown.
      If this is not manually called before Terra-- needs to load a configuration file, the config root will be automatically set to $CWD/terraminusminus/config, and further attempts to call this method will result in an IllegalStateException being thrown.
      This method and its implementation are unique to Terra--, as Terra++ is hardcoded to use .minecraft/terraplusplus/config.
      Parameters:
      configDir - the root of the cache
    • read

      public static CompletableFuture<io.netty.buffer.ByteBuf> read(@NonNull @NonNull Path file)
      Asynchronously reads a file's contents into a ByteBuf.
      Parameters:
      file - the file
      Returns:
      a CompletableFuture which will be notified when the file has been read
    • write

      public static void write(@NonNull @NonNull Path file, @NonNull @NonNull io.netty.buffer.ByteBuf data)
      Asynchronously writes a file's contents, replacing the existing file if it already exists.
      Parameters:
      file - the file
      data - the data
    • cacheFileFor

      public static Path cacheFileFor(@NonNull @NonNull String url)
      Gets the file path which stores the cached data for the given url.
      Parameters:
      url - the url
      Returns:
      the cache file
    • configFile

      public static Path configFile(@NonNull @NonNull String name)
      Gets the path to an additional configuration file with the given name.
      Parameters:
      name - the configuration file's name
      Returns:
      the path to the configuration file