Interface AssetStorage


public interface AssetStorage
A storage that is able to hold any "asset"-data for a map. For example images, icons, scripts or json-files.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if an asset exists in this storage without reading it.
    This is useful if the asset has a lot of data and using readAsset(String) just to check if the asset is present would be wasteful.
    void
    Deletes the asset with the given name from this storage, if it exists.
    If there is no asset with this name, this method does nothing.
    Returns the relative URL that can be used by the webapp to request this asset.
    This is the url that you can e.g.
    Reads an asset from this storage.
    Use the returned InputStream to read the asset-data.

    Example:
    Writes a new asset into this storage, overwriting any existent assets with the same name.
    Use the returned OutputStream to write the asset-data.
  • Method Details

    • writeAsset

      OutputStream writeAsset(String name) throws IOException
      Writes a new asset into this storage, overwriting any existent assets with the same name.
      Use the returned OutputStream to write the asset-data. The asset will be added to the storage as soon as that stream gets closed!

      Example:
       try (OutputStream out = assetStorage.writeAsset("image.png")) {
           ImageIO.write(image, "png", out);
       }
       
      Parameters:
      name - The (unique) name for this asset
      Returns:
      An OutputStream that should be used to write the asset and closed once!
      Throws:
      IOException - when the underlying storage rises an IOException
    • readAsset

      Optional<InputStream> readAsset(String name) throws IOException
      Reads an asset from this storage.
      Use the returned InputStream to read the asset-data.

      Example:
       Optional<InputStream> optIn = assetStorage.readAsset("image.png");
       if (optIn.isPresent()) {
           try (InputStream in = optIn.get()) {
               BufferedImage image = ImageIO.read(in);
           }
       }
       
      Parameters:
      name - The name of the asset that should be read from the storage.
      Returns:
      An Optional with an InputStream when the asset is found, from which the asset can be read. Or an empty optional if there is no asset with this name.
      Throws:
      IOException - when the underlying storage rises an IOException
    • assetExists

      boolean assetExists(String name) throws IOException
      Checks if an asset exists in this storage without reading it.
      This is useful if the asset has a lot of data and using readAsset(String) just to check if the asset is present would be wasteful.
      Parameters:
      name - The name of the asset to check for
      Returns:
      true if the asset is found, false if not
      Throws:
      IOException - when the underlying storage rises an IOException
    • getAssetUrl

      String getAssetUrl(String name)
      Returns the relative URL that can be used by the webapp to request this asset.
      This is the url that you can e.g. use in POIMarkers or HtmlMarkers to add an icon.
      If there is no asset with this name, then this method returns the URL that an asset with such a name would have if it would be added later.
      Parameters:
      name - The name of the asset
      Returns:
      The relative URL for an asset with the given name
    • deleteAsset

      void deleteAsset(String name) throws IOException
      Deletes the asset with the given name from this storage, if it exists.
      If there is no asset with this name, this method does nothing.
      Parameters:
      name - The name of the asset that should be deleted
      Throws:
      IOException - when the underlying storage rises an IOException