# Class MutableResource

java.lang.Object
com.codename1.ui.util.Resources
com.codename1.ui.util.MutableResource

Direct Known Subclasses:
  `MutableResouce`

public class MutableResource extends Resources

Mutable variant of `Resources` intended for non-designer environments.

This class provides a minimal API for programmatically editing resource files inside Codename One core code where JavaSE/Swing designer classes are not available.

### Supported resource categories

- `IMAGE`
- `DATA`
- `L10N`
- `THEME` (in-memory editing only; save serialization is intentionally limited)

### Explicitly unsupported categories

The following are intentionally rejected with `UnsupportedOperationException` when read or written:

- Timeline
- Indexed images
- SVG
- GUI Builder UI resources

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MutableResource()`
  Creates an empty mutable resource container.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  `boolean`
  `containsResource(String name)`
  `InputStream`
  `getData(String id)`
  Returns the data resource from the file
  `byte[]`
  `getDataByteArray(String id)`
  `boolean`
  `isModified()`
  `static MutableResource`
  `open(InputStream resource)`
  Opens a mutable resource from an input stream.
  `void`
  `save(OutputStream out)`
  `protected void`
  `saveL10N(DataOutputStream output, Hashtable l10n)`
  `void`
  `setData(String name, byte[] data)`
  `void`
  `setImage(String name, Image value)`
  `void`
  `setIndexedImage(String name, Image image)`
  `void`
  `setL10N(String name, Hashtable l10n)`
  `void`
  `setSVG(String name, Image image)`
  `void`
  `setTheme(String name, Hashtable theme)`
  `void`
  `setThemeProperty(String themeName, String key, Object value)`
  `void`
  `setTimeline(String name, Timeline timeline)`
  `void`
  `setUi(String name, byte[] data)`
  `protected void`
  `writeImage(DataOutputStream output, Image image)`

  ### Methods inherited from class Resources

  `getDataResourceNames, getFont, getFontResourceNames, getGlobalResources, getImage, getImageResourceNames, getL10N, getL10NResourceNames, getMajorVersion, getMetaData, getMinorVersion, getResourceNames, getSystemResource, getTheme, getThemeResourceNames, getUIResourceNames, isAnimation, isData, isEnableMediaQueries, isFailOnMissingTruetype, isFont, isImage, isL10N, isTheme, isUI, l10NLocaleSet, listL10NLocales, open, open, open, openLayered, openLayered, override, setEnableMediaQueries, setFailOnMissingTruetype, setGlobalResources, setPassword, setRuntimeMultiImageEnabled`
  Modifier and Type
  Method
  Description
  `String[]`
  `getDataResourceNames()`
  Returns the names of the data resources within this bundle
  `Font`
  `getFont(String id)`
  Returns the font resource from the file
  `String[]`
  `getFontResourceNames()`
  Returns the names of the fonts within this bundle
  `static Resources`
  `getGlobalResources()`
  Global resources are used by new GUI builder apps to keep track of the applications resources
  `Image`
  `getImage(String id)`
  Returns the image resource from the file
  `String[]`
  `getImageResourceNames()`
  Returns the names of the images within this bundle
  `Hashtable<String,String>`
  `getL10N(String id, String locale)`
  Returns a hashmap containing localized String key/value pairs for the given locale name
  `String[]`
  `getL10NResourceNames()`
  Returns the names of the localization bundles within this bundle
  `int`
  `getMajorVersion()`
  Returns the version number for this resource file.
  `String[]`
  `getMetaData()`
  Returns optional meta-data associated with the resource file
  `int`
  `getMinorVersion()`
  Returns the minor version number for this resource file This value relates to the value from the header defined by the resource file specification.
  `String[]`
  `getResourceNames()`
  Returns the names of the resources within this bundle
  `static Resources`
  `getSystemResource()`
  Gets the system resource which can be located /CN1Images.res.
  `Hashtable`
  `getTheme(String id)`
  Returns the theme resource from the file
  `String[]`
  `getThemeResourceNames()`
  Returns the names of the images within this bundle
  `String[]`
  `getUIResourceNames()`
  Returns the names of the ui resources within this bundle
  `boolean`
  `isAnimation(String name)`
  Returns true if this is an animation resource
  `boolean`
  `isData(String name)`
  Returns true if this is a data resource
  `static boolean`
  `isEnableMediaQueries()`
  `static boolean`
  `isFailOnMissingTruetype()`

  ###### Returns

  `boolean`
  `isFont(String name)`
  Returns true if this is a font resource
  `boolean`
  `isImage(String name)`
  Returns true if this is an image resource
  `boolean`
  `isL10N(String name)`
  Returns true if this is a generic data resource
  `boolean`
  `isTheme(String name)`
  Returns true if this is a theme resource
  `boolean`
  `isUI(String name)`
  Returns true if this is a UI resource
  `Collection<String>`
  `l10NLocaleSet(String id)`
  Returns a collection of the l10 locale names
  `Enumeration`
  `listL10NLocales(String id)`
  Returns an enumration of the locales supported by this resource id
  `static Resources`
  `open(InputStream resource, int dpi)`
  Creates a resource object from the given input stream
  `static Resources`
  `open(String resource)`
  Creates a resource object from the local JAR resource identifier
  `static Resources`
  `open(String resource, int dpi)`
  Creates a resource object from the local JAR resource identifier
  `static Resources`
  `openLayered(String resource)`
  Opens a multi-layer resource file that supports overriding features on a specific platform.
  `static Resources`
  `openLayered(String resource, int dpi)`
  Opens a multi-layer resource file that supports overriding features on a specific platform.
  `void`
  `override(InputStream input)`
  This method allows overriding the data of a resource file with another resource file thus replacing or enhancing existing content with platform specific content.
  `static void`
  `setEnableMediaQueries(boolean enable)`
  `static void`
  `setFailOnMissingTruetype(boolean aFailOnMissingTruetype)`

  ###### Parameters

  `static void`
  `setGlobalResources(Resources res)`
  Global resources are used by new GUI builder apps to keep track of the applications resources
  `static void`
  `setPassword(String password)`
  Sets the password to use for password protected resource files
  `static void`
  `setRuntimeMultiImageEnabled(boolean b)`
  This flag should be off and it is off by default, some special case implementations for development e.g.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `int`
  `hashCode()`
  Returns a hash code value for the object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Constructor Details

  - ### MutableResource

    public MutableResource()
    Creates an empty mutable resource container.

- ## Method Details

  - ### open

    public static MutableResource open(InputStream resource) throws IOException
    Opens a mutable resource from an input stream.
    Parameters:
      `resource` - source stream.
    Returns:
      loaded mutable resource.
    Throws:
      `IOException` - if parsing fails.

  - ### setImage

    public void setImage(String name, Image value)

  - ### setData

    public void setData(String name, byte[] data)

  - ### setTheme

    public void setTheme(String name, Hashtable theme)

  - ### setThemeProperty

    public void setThemeProperty(String themeName, String key, Object value)

  - ### setL10N

    public void setL10N(String name, Hashtable l10n)

  - ### getDataByteArray

    public byte[] getDataByteArray(String id)

  - ### containsResource

    public boolean containsResource(String name)

  - ### isModified

    public boolean isModified()

  - ### setUi

    public void setUi(String name, byte[] data)

  - ### setTimeline

    public void setTimeline(String name, Timeline timeline)

  - ### setIndexedImage

    public void setIndexedImage(String name, Image image)

  - ### setSVG

    public void setSVG(String name, Image image)

  - ### clear

    public void clear()

  - ### save

    public void save(OutputStream out) throws IOException
    Throws:
      `IOException`

  - ### writeImage

    protected void writeImage(DataOutputStream output, Image image) throws IOException
    Throws:
      `IOException`

  - ### saveL10N

    protected void saveL10N(DataOutputStream output, Hashtable l10n) throws IOException
    Throws:
      `IOException`

  - ### getData

    public InputStream getData(String id)
    Description copied from class: `Resources`

    Returns the data resource from the file

    ###### Parameters

    - `id`: name of the data resource

    ###### Returns

    newly created input stream that allows reading the data of the resource

    Overrides:
      `getData` in class `Resources`