org.opensourcephysics.tools
Class Resource

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

public class Resource
extends java.lang.Object

This represents a resource obtained from a URL or File.

Version:
1.0
Author:
Douglas Brown

Constructor Summary
  Resource(java.io.File file)
          Constructs a resource from a file.
  Resource(java.net.URL url)
          Constructs a resource from a url.
protected Resource(java.net.URL zipURL, java.lang.String content)
          Constructs a resource from a ZIP url with content.
 
Method Summary
 java.lang.String getAbsolutePath()
          Gets the absolute path.
 java.applet.AudioClip getAudioClip()
          Gets an AudioClip.
 java.awt.image.BufferedImage getBufferedImage()
          Gets a buffered image.
 java.awt.image.BufferedImage getBufferedImage(int bufferedImageType)
          Gets a buffered image.
static java.nio.charset.Charset getCharset()
          Gets the character set used for reading input streams.
 java.io.File getFile()
          Gets the file associated with this resource.
 javax.swing.ImageIcon getIcon()
          Gets an ImageIcon.
 java.awt.Image getImage()
          Gets an Image.
 java.lang.Object getObject(java.lang.Class<?> type)
          Gets an object of the specified type.
 java.lang.String getString()
          Gets a String.
 java.net.URL getURL()
          Gets the url associated with this resource.
 java.io.InputStream openInputStream()
          Opens an InputStream.
 java.io.BufferedReader openReader()
          Opens a BufferedReader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resource

public Resource(java.net.URL url)
Constructs a resource from a url.

Parameters:
url - the URL

Resource

public Resource(java.io.File file)
Constructs a resource from a file.

Parameters:
file - the file

Resource

protected Resource(java.net.URL zipURL,
                   java.lang.String content)
Constructs a resource from a ZIP url with content.

Parameters:
zipURL - the URL
content - the path of the contents relative to the ZIP file
Method Detail

getCharset

public static java.nio.charset.Charset getCharset()
Gets the character set used for reading input streams.

Returns:
the character set

getAbsolutePath

public java.lang.String getAbsolutePath()
Gets the absolute path.

Returns:
the absolute path

getURL

public java.net.URL getURL()
Gets the url associated with this resource.

Returns:
the URL

getFile

public java.io.File getFile()
Gets the file associated with this resource.

Returns:
the File

getObject

public java.lang.Object getObject(java.lang.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 java.io.InputStream openInputStream()
Opens an InputStream.

Returns:
the stream

openReader

public java.io.BufferedReader openReader()
Opens a BufferedReader.

Returns:
the reader

getIcon

public javax.swing.ImageIcon getIcon()
Gets an ImageIcon.

Returns:
the icon

getImage

public java.awt.Image getImage()
Gets an Image.

Returns:
the image

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Gets a buffered image.

Returns:
the image

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage(int bufferedImageType)
Gets a buffered image.

Parameters:
bufferedImageType - one of the types defined by the BufferedImage class
Returns:
the image

getString

public java.lang.String getString()
Gets a String.

Returns:
the string

getAudioClip

public java.applet.AudioClip getAudioClip()
Gets an AudioClip.

Returns:
the audio clip