uk.ac.starlink.util

## Class FileDataSource

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

- Direct Known Subclasses:
    TemporaryFileDataSource

      public class FileDataSource
      extends DataSource

  A DataSource implementation based on a `File`.

- - ### Field Summary

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

      `DEFAULT_INTRO_LIMIT, MARK_WORKAROUND_PROPERTY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileDataSource(java.io.File file)` Creates a new FileDataSource from a File object.
    `FileDataSource(java.io.File file, java.lang.String position)` Creates a new FileDataSource from a File object and a position string.
    `FileDataSource(java.lang.String filename)` Creates a new FileDataSource from a filename.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.io.File` | `getFile()` Returns the File object on which this `FileDataSource` is based.
    `protected java.io.InputStream` | `getRawInputStream()` Provides a new InputStream for this data source.
    `long` | `getRawLength()` Returns the length of this file.
    `java.net.URL` | `getURL()` Returns a URL which corresponds to this data source, if one exists.

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

      `close, forceCompression, getCompression, getHybridInputStream, getInputStream, getInputStream, getIntro, getIntroLimit, getLength, getMarkWorkaround, getName, getPosition, 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

    - #### FileDataSource

          public FileDataSource(java.io.File file,
                                java.lang.String position)
                         throws java.io.IOException

      Creates a new FileDataSource from a File object and a position string.
      Parameters:
        `file` - the file
        `position` - the source's position attribute (indicates the relevant part of the file)
      Throws:
        `java.io.IOException` - if `file` does not exist, cannot be read, or is a directory

    - #### FileDataSource

          public FileDataSource(java.io.File file)
                         throws java.io.IOException

      Creates a new FileDataSource from a File object.
      Parameters:
        `file` - the file
      Throws:
        `java.io.IOException` - if `file` does not exist, cannot be read, or is a directory

    - #### FileDataSource

          public FileDataSource(java.lang.String filename)
                         throws java.io.IOException

      Creates a new FileDataSource from a filename.
      Parameters:
        `filename` - filename
      Throws:
        `java.io.IOException` - if `filename` does not name a readable file

  - ### Method Detail

    - #### getRawInputStream

          protected 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`

    - #### getRawLength

          public long getRawLength()

      Returns the length of this file. return file length
      Overrides:
        `getRawLength` in class `DataSource`
      Returns:
        the length of the raw input stream, or -1

    - #### getFile

          public java.io.File getFile()

      Returns the File object on which this `FileDataSource` is based.
      Returns:
        the file

    - #### 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`