Package de.bluecolored.bluemap.api
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 TypeMethodDescriptionbooleanassetExists(String name) Checks if an asset exists in this storage without reading it.
This is useful if the asset has a lot of data and usingreadAsset(String)just to check if the asset is present would be wasteful.voiddeleteAsset(String name) 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.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.writeAsset(String name) Writes a new asset into this storage, overwriting any existent assets with the same name.
Use the returnedOutputStreamto write the asset-data.
-
Method Details
-
writeAsset
Writes a new asset into this storage, overwriting any existent assets with the same name.
Use the returnedOutputStreamto 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
OutputStreamthat should be used to write the asset and closed once! - Throws:
IOException- when the underlying storage rises an IOException
-
readAsset
Reads an asset from this storage.
Use the returnedInputStreamto 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
Optionalwith anInputStreamwhen 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
Checks if an asset exists in this storage without reading it.
This is useful if the asset has a lot of data and usingreadAsset(String)just to check if the asset is present would be wasteful.- Parameters:
name- The name of the asset to check for- Returns:
trueif the asset is found,falseif not- Throws:
IOException- when the underlying storage rises an IOException
-
getAssetUrl
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 inPOIMarkers orHtmlMarkers 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
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
-