Class ImageStore

java.lang.Object
dev.despical.pixelpainter.image.ImageStore

public final class ImageStore extends Object
Owns local PNG, JPEG and WebP files and bounded downloads from trusted HTTPS hosts.

Names use a flat namespace. Resolution excludes symbolic links and requires an explicit extension when a base name is ambiguous. Decode checks byte size, format and source dimensions before reading pixels.

Downloads validate redirect destinations, reject local addresses, enforce byte and read-time limits, and decode a temporary file before promoting it. Existing files are never replaced. These blocking operations belong on image workers and do not access Bukkit worlds. Trust the configured host owners.

  • Constructor Details

    • ImageStore

      public ImageStore(Path folder) throws IOException
      Creates the source directory and resolves its real filesystem location.
      Parameters:
      folder - source-image directory
      Throws:
      IOException - if the directory cannot be created or resolved
  • Method Details

    • validName

      public static String validName(String input)
      Validates a flat source name with an optional PNG, JPEG or WebP extension.
      Parameters:
      input - letters, digits, underscores or hyphens with an optional extension
      Returns:
      unchanged input
      Throws:
      IllegalArgumentException - if the name violates the filename policy
    • list

      public List<String> list() throws IOException
      Lists valid, regular source files without following symbolic links.
      Returns:
      source names sorted without regard to case
      Throws:
      IOException - if directory scanning fails
    • resolve

      public Path resolve(String name) throws IOException
      Resolves a case-insensitive name or an unambiguous extensionless base name.
      Parameters:
      name - validated source name
      Returns:
      path of the existing source image
      Throws:
      IOException - if scanning fails
      IllegalArgumentException - if the name is invalid, missing or ambiguous
    • read

      public BufferedImage read(String name, Settings settings) throws IOException
      Resolves and decodes a source image using captured limits.
      Parameters:
      name - source name
      settings - request settings
      Returns:
      decoded image
      Throws:
      IOException - if the file cannot be read
      IllegalArgumentException - if name, format or size validation fails
    • decode

      public static BufferedImage decode(Path file, Settings settings) throws IOException
      Validates byte size, format and source dimensions before reading pixels.
      Parameters:
      file - existing image file
      settings - source limits
      Returns:
      decoded first image
      Throws:
      IOException - if metadata or content cannot be read
      IllegalArgumentException - if format, bytes or dimensions are unsupported
    • delete

      public void delete(String name) throws IOException
      Deletes a resolved source without changing paintings or undo journals.
      Parameters:
      name - source name
      Throws:
      IOException - if deletion or resolution fails
      IllegalArgumentException - if the name is invalid, missing or ambiguous
    • download

      public String download(String name, String link, Settings settings) throws Exception
      Downloads and validates an image before moving it into the source directory.
      Parameters:
      name - destination name; an absent extension becomes .png
      link - trusted HTTPS source URL
      settings - captured download hosts and limits
      Returns:
      saved destination filename
      Throws:
      Exception - if network access, validation, decoding or promotion fails