Class FileDataSource
java.lang.Object
uk.ac.starlink.util.DataSource
uk.ac.starlink.util.FileDataSource
- Direct Known Subclasses:
TemporaryFileDataSource
A DataSource implementation based on a
File.- Author:
- Mark Taylor (Starlink)
-
Field Summary
Fields inherited from class DataSource
DEFAULT_INTRO_LIMIT, MARK_WORKAROUND_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionFileDataSource(File file) Creates a new FileDataSource from a File object.FileDataSource(File file, String position) Creates a new FileDataSource from a File object and a position string.FileDataSource(String filename) Creates a new FileDataSource from a filename. -
Method Summary
Modifier and TypeMethodDescriptiongetFile()Returns the File object on which thisFileDataSourceis based.protected InputStreamProvides a new InputStream for this data source.longReturns the length of this file.getURL()Returns a URL which corresponds to this data source, if one exists.Methods inherited from class DataSource
close, forceCompression, getCompression, getHybridInputStream, getInputStream, getInputStream, getIntro, getIntroLimit, getLength, getMarkWorkaround, getName, getPosition, getSystemId, makeDataSource, makeDataSource, makeDataSource, setCompression, setIntroLimit, setMarkWorkaround, setName, setPosition, toString
-
Constructor Details
-
FileDataSource
Creates a new FileDataSource from a File object and a position string.- Parameters:
file- the fileposition- the source's position attribute (indicates the relevant part of the file)- Throws:
IOException- iffiledoes not exist, cannot be read, or is a directory
-
FileDataSource
Creates a new FileDataSource from a File object.- Parameters:
file- the file- Throws:
IOException- iffiledoes not exist, cannot be read, or is a directory
-
FileDataSource
Creates a new FileDataSource from a filename.- Parameters:
filename- filename- Throws:
IOException- iffilenamedoes not name a readable file
-
-
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
-
getRawLength
public long getRawLength()Returns the length of this file. return file length- Overrides:
getRawLengthin classDataSource- Returns:
- the length of the raw input stream, or -1
-
getFile
Returns the File object on which thisFileDataSourceis based.- Returns:
- the file
-
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
-