uk.ac.starlink.util

## Class ResourceDataSource

- java.lang.Object
- - uk.ac.starlink.util.DataSource
  - - uk.ac.starlink.util.ResourceDataSource

-     public class ResourceDataSource
      extends DataSource

  A DataSource which represents a resource available from the class loader's `ClassLoader.getResourceAsStream(java.lang.String)` method.

- - ### Field Summary

    - ### Fields inherited from class uk.ac.starlink.util.DataSource

      `DEFAULT_INTRO_LIMIT, MARK_WORKAROUND_PROPERTY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceDataSource(java.lang.String resource)` Constructs a new ResourceDataSource from a resource name with a default size of intro buffer.
    `ResourceDataSource(java.lang.String resource, int introLimit)` Constructs a new ResourceDataSource from a resource name and given size of intro buffer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `exists()` Indicates whether this resource can be located by the class loader or not.
    `java.lang.ClassLoader` | `getClassLoader()` Returns the ClassLoader which is used for resource resolution.
    `java.io.InputStream` | `getRawInputStream()` Provides a new InputStream for this data source.
    `java.net.URL` | `getURL()` Returns a URL which corresponds to this data source, if one exists.
    `void` | `setClassLoader(java.lang.ClassLoader classLoader)` Sets the ClassLoader which is used for resource resolution.

    - ### Methods inherited from class uk.ac.starlink.util.DataSource

      `close, forceCompression, getCompression, getHybridInputStream, getInputStream, getInputStream, getIntro, getIntroLimit, getLength, getMarkWorkaround, getName, getPosition, getRawLength, getSystemId, makeDataSource, makeDataSource, makeDataSource, setCompression, setIntroLimit, setMarkWorkaround, setName, setPosition, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ResourceDataSource

          public ResourceDataSource(java.lang.String resource,
                                    int introLimit)

      Constructs a new ResourceDataSource from a resource name and given size of intro buffer. Note that like `ClassLoader.getResource(java.lang.String)` but unlike `Class.getResource(java.lang.String)` the resource name is assumed absolute, and should '/'.
      Parameters:
        `resource` - the path of the resource represented by this DataSource
        `introLimit` - the intro buffer size

    - #### ResourceDataSource

          public ResourceDataSource(java.lang.String resource)

      Constructs a new ResourceDataSource from a resource name with a default size of intro buffer. Note that like `ClassLoader.getResource(java.lang.String)` but unlike `Class.getResource(java.lang.String)` the resource name is assumed absolute, and should '/'.
      Parameters:
        `resource` - the path of the resource represented by this DataSource

  - ### Method Detail

    - #### getRawInputStream

          public java.io.InputStream getRawInputStream()
                                                throws java.io.IOException

      Description copied from class: `DataSource`
      Provides a new InputStream for this data source. This method should be implemented by subclasses to provide a new InputStream giving the raw content of the source each time it is called. The general contract of this method is that each time it is called it will return a stream with the same content.
      Specified by:
        `getRawInputStream` in class `DataSource`
      Returns:
        an InputStream containing the data of this source
      Throws:
        `java.io.IOException`

    - #### getURL

          public java.net.URL getURL()

      Description copied from class: `DataSource`
      Returns a URL which corresponds to this data source, if one exists. An `URL.openConnection()` method call on the URL returned by this method should provide a stream with the same content as the `DataSource.getRawInputStream()` method of this data source. If no such URL exists or is known, then `null` should be returned.

      If this source has a non-null position value, it will be appended to the main part of the URL after a '#' character (as the URL's ref part).

      Overrides:
        `getURL` in class `DataSource`
      Returns:
        a URL corresponding to this source, or `null`

    - #### exists

          public boolean exists()

      Indicates whether this resource can be located by the class loader or not.
      Returns:
        true iff the getRawInputStream method will return an input stream

    - #### getClassLoader

          public java.lang.ClassLoader getClassLoader()

      Returns the ClassLoader which is used for resource resolution.
      Returns:
        the class loader

    - #### setClassLoader

          public void setClassLoader(java.lang.ClassLoader classLoader)

      Sets the ClassLoader which is used for resource resolution.
      Parameters:
        `classLoader` - the class loader