Class ResourceDataSource
java.lang.Object
uk.ac.starlink.util.DataSource
uk.ac.starlink.util.ResourceDataSource
A DataSource which represents a resource available from the
class loader's
ClassLoader.getResourceAsStream(String) method.- Author:
- Mark Taylor (Starlink)
-
Field Summary
Fields inherited from class DataSource
DEFAULT_INTRO_LIMIT, MARK_WORKAROUND_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionResourceDataSource(String resource) Constructs a new ResourceDataSource from a resource name with a default size of intro buffer.ResourceDataSource(String resource, int introLimit) Constructs a new ResourceDataSource from a resource name and given size of intro buffer. -
Method Summary
Modifier and TypeMethodDescriptionbooleanexists()Indicates whether this resource can be located by the class loader or not.Returns the ClassLoader which is used for resource resolution.Provides a new InputStream for this data source.getURL()Returns a URL which corresponds to this data source, if one exists.voidsetClassLoader(ClassLoader classLoader) Sets the ClassLoader which is used for resource resolution.Methods inherited from class DataSource
close, forceCompression, getCompression, getHybridInputStream, getInputStream, getInputStream, getIntro, getIntroLimit, getLength, getMarkWorkaround, getName, getPosition, getRawLength, getSystemId, makeDataSource, makeDataSource, makeDataSource, setCompression, setIntroLimit, setMarkWorkaround, setName, setPosition, toString
-
Constructor Details
-
ResourceDataSource
Constructs a new ResourceDataSource from a resource name and given size of intro buffer. Note that likeClassLoader.getResource(String)but unlikeClass.getResource(String)the resource name is assumed absolute, and should '/'.- Parameters:
resource- the path of the resource represented by this DataSourceintroLimit- the intro buffer size
-
ResourceDataSource
Constructs a new ResourceDataSource from a resource name with a default size of intro buffer. Note that likeClassLoader.getResource(String)but unlikeClass.getResource(String)the resource name is assumed absolute, and should '/'.- Parameters:
resource- the path of the resource represented by this DataSource
-
-
Method Details
-
getRawInputStream
Description copied from class:DataSourceProvides 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:
getRawInputStreamin classDataSource- Returns:
- an InputStream containing the data of this source
- Throws:
IOException
-
getURL
Description copied from class:DataSourceReturns a URL which corresponds to this data source, if one exists. AnURL.openConnection()method call on the URL returned by this method should provide a stream with the same content as theDataSource.getRawInputStream()method of this data source. If no such URL exists or is known, thennullshould 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:
getURLin classDataSource- 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
Returns the ClassLoader which is used for resource resolution.- Returns:
- the class loader
-
setClassLoader
Sets the ClassLoader which is used for resource resolution.- Parameters:
classLoader- the class loader
-