Class Resource

java.lang.Object
org.opensourcephysics.tools.Resource

public class Resource extends Object
This represents a resource obtained from a URL or File.
Version:
1.0
Author:
Douglas Brown
  • Constructor Details

    • Resource

      public Resource(URL url)
      Constructs a resource from a url.
      Parameters:
      url - the URL
    • Resource

      public Resource(File file)
      Constructs a resource from a file.
      Parameters:
      file - the file
    • Resource

      protected Resource(URL zipURL, String content)
      Constructs a resource from a ZIP [url]!/[content].
      Parameters:
      zipURL - the URL
      content - the path of the contents relative to the ZIP file
  • Method Details

    • getCharset

      public static Charset getCharset()
      Gets the character set used for reading input streams.
      Returns:
      the character set
    • getAbsolutePath

      public String getAbsolutePath()
      Gets the absolute path.
      Returns:
      the absolute path
    • getURL

      public URL getURL()
      Gets the url associated with this resource.
      Returns:
      the URL
    • getFile

      public File getFile()
      Gets the file associated with this resource.
      Returns:
      the File
    • getObject

      public Object getObject(Class<?> type)
      Gets an object of the specified type. Currently the only types recognized are String and ImageIcon.
      Parameters:
      type - the desired class type
      Returns:
      the object, or null
    • openInputStream

      public InputStream openInputStream()
      Opens an InputStream.
      Returns:
      the stream
    • openReader

      public BufferedReader openReader()
      Opens a BufferedReader for the default character set (UTF-8).
      Returns:
      the reader
    • getImageIcon

      public ImageIcon getImageIcon()
      Gets an ImageIcon.
      Returns:
      the icon
    • getResizableIcon

      public ResizableIcon getResizableIcon()
      Gets a ResizableIcon.
      Returns:
      the icon
    • getImage

      public Image getImage()
      Gets an Image.
      Returns:
      the image
    • getBufferedImage

      public BufferedImage getBufferedImage()
      Gets a buffered image.
      Returns:
      the image
    • getBufferedImage

      public BufferedImage getBufferedImage(int bufferedImageType)
      Gets a buffered image.
      Parameters:
      bufferedImageType - one of the types defined by the BufferedImage class
      Returns:
      the image
    • getString

      public String getString()
      Gets a String.
      Returns:
      the string
    • getString

      public String getString(String encoding)
      Gets a String encoded with a specified encoding.
      Parameters:
      encoding - the encoding (eg "ISO-8859-1" for properties files)
      Returns:
      the string
    • getXMLClassName

      public String getXMLClassName()
      Gets the short name of the XMLControl class. May be null.
      Returns:
      the class name
    • getAudioClip

      public AudioClip getAudioClip()
      Gets an AudioClip.
      Returns:
      the audio clip
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • newImageResource

      public static Resource newImageResource(byte[] bytes)
      Just for a Video image
      Parameters:
      bytes -
      Returns: