org.rrd4j.core.jrrd

## Class RRDatabase

- java.lang.Object
- - org.rrd4j.core.jrrd.RRDatabase

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class RRDatabase
      extends Object
      implements Closeable

  Instances of this class model Round Robin Database (RRD) files.
  Version:
    $Revision: 1.1 $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) Header` | `header`
    `(package private) Date` | `lastUpdate` Timestamp of last data modification
    `(package private) RRDFile` | `rrdFile`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RRDatabase(File file)` Creates a database to read from.
    `RRDatabase(String name)` Creates a database to read from.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes this database stream and releases any associated system resources.
    `Archive` | `getArchive(int index)` Returns the `Archive` at the specified position in this database.
    `Archive` | `getArchive(String name)` getArchive.
    `(package private) ArrayList<Archive>` | `getArchiveList(ConsolidationFunctionType type)`
    `Iterator<Archive>` | `getArchives()` Returns an iterator over the archives in this database in proper sequence.
    `Iterator<Archive>` | `getArchives(ConsolidationFunctionType type)` Returns an iterator over the archives in this database of the given type in proper sequence.
    `DataChunk` | `getData(ConsolidationFunctionType type)` Returns data from the database corresponding to the given consolidation function and a step size of 1.
    `DataChunk` | `getData(ConsolidationFunctionType type, Date startDate, Date endDate, long step)` Returns data from the database corresponding to the given consolidation function.
    `DataChunk` | `getData(ConsolidationFunctionType type, long startTime, long endTime, long stepSeconds)` getData.
    `DataSource` | `getDataSource(int index)` Returns the `DataSource` at the specified position in this database.
    `Iterator<DataSource>` | `getDataSources()` Returns an iterator over the data sources in this database in proper sequence.
    `Set<String>` | `getDataSourcesName()` getDataSourcesName.
    `Header` | `getHeader()` Returns the `Header` for this database.
    `Date` | `getLastUpdate()` Returns the date this database was last updated.
    `int` | `getNumArchives()` Returns the number of archives in this database.
    `void` | `printInfo(PrintStream s)` Outputs the header information of the database to the given print stream using the default number format.
    `void` | `printInfo(PrintStream s, NumberFormat numberFormat)` Outputs the header information of the database to the given print stream using the given number format.
    `String` | `toString()` Returns a summary the contents of this database.
    `void` | `toXml(PrintStream s)` Outputs the content of the database to the given print stream as a stream of XML.

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

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

- - ### Field Detail

    - #### header

          final Header header

    - #### lastUpdate

          final Date lastUpdate

      Timestamp of last data modification

    - #### rrdFile

          final RRDFile rrdFile

  - ### Constructor Detail

    - #### RRDatabase

          public RRDatabase(File file)
                     throws IOException

      Creates a database to read from.
      Parameters:
        `file` - the file to read from.
      Throws:
        `IOException` - if an I/O error occurs.

    - #### RRDatabase

          public RRDatabase(String name)
                     throws IOException

      Creates a database to read from.
      Parameters:
        `name` - the filename of the file to read from.
      Throws:
        `IOException` - if an I/O error occurs.

  - ### Method Detail

    - #### close

          public void close()
                     throws IOException

      Closes this database stream and releases any associated system resources.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException` - if an I/O error occurs.

    - #### getArchive

          public Archive getArchive(int index)

      Returns the `Archive` at the specified position in this database.
      Parameters:
        `index` - index of `Archive` to return.
      Returns:
        the `Archive` at the specified position in this database.

    - #### getArchive

          public Archive getArchive(String name)

      getArchive.
      Parameters:
        `name` - a `String` object.
      Returns:
        a `Archive` object.

    - #### getArchiveList

          ArrayList<Archive> getArchiveList(ConsolidationFunctionType type)

    - #### getArchives

          public Iterator<Archive> getArchives()

      Returns an iterator over the archives in this database in proper sequence.
      Returns:
        an iterator over the archives in this database in proper sequence.

    - #### getArchives

          public Iterator<Archive> getArchives(ConsolidationFunctionType type)

      Returns an iterator over the archives in this database of the given type in proper sequence.
      Parameters:
        `type` - the consolidation function that should have been applied to the data.
      Returns:
        an iterator over the archives in this database of the given type in proper sequence.

    - #### getData

          public DataChunk getData(ConsolidationFunctionType type)
                            throws IOException

      Returns data from the database corresponding to the given consolidation function and a step size of 1.
      Parameters:
        `type` - the consolidation function that should have been applied to the data.
      Returns:
        the raw data.
      Throws:
        `IllegalArgumentException` - if there was a problem locating a data archive with the requested consolidation function.
        `IOException` - if there was a problem reading data from the database.

    - #### getData

          public DataChunk getData(ConsolidationFunctionType type,
                                   Date startDate,
                                   Date endDate,
                                   long step)
                            throws IOException

      Returns data from the database corresponding to the given consolidation function.
      Parameters:
        `type` - the consolidation function that should have been applied to the data.
        `step` - the step size to use.
        `startDate` - a `Date` object.
        `endDate` - a `Date` object.
      Returns:
        the raw data.
      Throws:
        `IllegalArgumentException` - if there was a problem locating a data archive with the requested consolidation function.
        `IOException` - if there was a problem reading data from the database.

    - #### getData

          public DataChunk getData(ConsolidationFunctionType type,
                                   long startTime,
                                   long endTime,
                                   long stepSeconds)
                            throws IOException

      getData.
      Parameters:
        `type` - a `ConsolidationFunctionType` object.
        `startTime` - seconds since epoch
        `endTime` - seconds since epoch
        `stepSeconds` - in seconds
      Returns:
        a `DataChunk` object.
      Throws:
        `IOException` - if any.

    - #### getDataSource

          public DataSource getDataSource(int index)

      Returns the `DataSource` at the specified position in this database.
      Parameters:
        `index` - index of `DataSource` to return.
      Returns:
        the `DataSource` at the specified position in this database

    - #### getDataSources

          public Iterator<DataSource> getDataSources()

      Returns an iterator over the data sources in this database in proper sequence.
      Returns:
        an iterator over the data sources in this database in proper sequence.

    - #### getDataSourcesName

          public Set<String> getDataSourcesName()

      getDataSourcesName.
      Returns:
        a `Set` object.

    - #### getHeader

          public Header getHeader()

      Returns the `Header` for this database.
      Returns:
        the `Header` for this database.

    - #### getLastUpdate

          public Date getLastUpdate()

      Returns the date this database was last updated. To convert this date to the form returned by `rrdtool last` call Date.getTime() and divide the result by 1000.
      Returns:
        the date this database was last updated.

    - #### getNumArchives

          public int getNumArchives()

      Returns the number of archives in this database.
      Returns:
        the number of archives in this database.

    - #### printInfo

          public void printInfo(PrintStream s)

      Outputs the header information of the database to the given print stream using the default number format. The default format for `double` is 0.0000000000E0.
      Parameters:
        `s` - the PrintStream to print the header information to.

    - #### printInfo

          public void printInfo(PrintStream s,
                                NumberFormat numberFormat)

      Outputs the header information of the database to the given print stream using the given number format. The format is almost identical to that produced by rrdtool info
      Parameters:
        `s` - the PrintStream to print the header information to.
        `numberFormat` - the format to print `double`s as.

    - #### toString

          public String toString()

      Returns a summary the contents of this database.
      Overrides:
        `toString` in class `Object`
      Returns:
        a summary of the information contained in this database.

    - #### toXml

          public void toXml(PrintStream s)

      Outputs the content of the database to the given print stream as a stream of XML. The XML format is almost identical to that produced by rrdtool dump

      A flush is issued at the end of the XML generation, so auto flush of the PrintStream can be set to false

      Parameters:
        `s` - the PrintStream to send the XML to.