Class DataFile


  • public class DataFile
    extends java.lang.Object
    DataFile main class
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DataFile()  
        DataFile​(ModelDataFile modelDataFile)
      Construct a DataFile object setting the model, does not load it
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRecord​(Record record)
      Add record.
      ModelDataFile getModelDataFile()
      Gets model data file.
      java.util.List<Record> getRecords()
      Gets records.
      static DataFile makeDataFile​(java.net.URL definitionUrl, java.lang.String dataFileName)
      Creates a DataFile object using the specified definition.
      Record makeRecord​(java.lang.String recordName)
      Make record record.
      RecordIterator makeRecordIterator​(java.io.InputStream dataFileStream, java.lang.String locationInfo)
      Make record iterator record iterator.
      RecordIterator makeRecordIterator​(java.net.URL fileUrl)
      Make record iterator record iterator.
      void readDataFile​(java.io.InputStream dataFileStream, java.lang.String locationInfo)
      Loads (or reloads) the data file from the given stream
      void readDataFile​(java.lang.String content)
      Populates (or reloads) the data file with the text of the given content
      void readDataFile​(java.net.URL fileUrl)
      Loads (or reloads) the data file at the pre-specified location.
      static DataFile readFile​(java.net.URL fileUrl, java.net.URL definitionUrl, java.lang.String dataFileName)
      Creates a DataFile object which will contain the parsed objects for the specified datafile, using the specified definition.
      java.lang.String writeDataFile()
      Returns the records in this DataFile object as a plain text data file content
      void writeDataFile​(java.io.OutputStream outStream)
      Writes the records in this DataFile object to the given OutputStream
      void writeDataFile​(java.lang.String filename)
      Writes the records in this DataFile object to a text data file
      protected void writeRecords​(java.io.OutputStream outStream, java.util.List<Record> records)
      Write records.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataFile

        public DataFile​(ModelDataFile modelDataFile)
        Construct a DataFile object setting the model, does not load it
        Parameters:
        modelDataFile - The model of the DataFile to instantiate
      • DataFile

        protected DataFile()
    • Method Detail

      • readFile

        public static DataFile readFile​(java.net.URL fileUrl,
                                        java.net.URL definitionUrl,
                                        java.lang.String dataFileName)
                                 throws DataFileException
        Creates a DataFile object which will contain the parsed objects for the specified datafile, using the specified definition.
        Parameters:
        fileUrl - The URL where the data file is located
        definitionUrl - The location of the data file definition XML file
        dataFileName - The data file model name, as specified in the definition XML file
        Returns:
        A new DataFile object with the specified file pre-loaded
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • makeDataFile

        public static DataFile makeDataFile​(java.net.URL definitionUrl,
                                            java.lang.String dataFileName)
                                     throws DataFileException
        Creates a DataFile object using the specified definition.
        Parameters:
        definitionUrl - The location of the data file definition XML file
        dataFileName - The data file model name, as specified in the definition XML file
        Returns:
        A new DataFile object
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • getModelDataFile

        public ModelDataFile getModelDataFile()
        Gets model data file.
        Returns:
        the model data file
      • getRecords

        public java.util.List<Record> getRecords()
        Gets records.
        Returns:
        the records
      • addRecord

        public void addRecord​(Record record)
        Add record.
        Parameters:
        record - the record
      • makeRecord

        public Record makeRecord​(java.lang.String recordName)
        Make record record.
        Parameters:
        recordName - the record name
        Returns:
        the record
      • readDataFile

        public void readDataFile​(java.net.URL fileUrl)
                          throws DataFileException
        Loads (or reloads) the data file at the pre-specified location.
        Parameters:
        fileUrl - The URL that the file will be loaded from
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • readDataFile

        public void readDataFile​(java.lang.String content)
                          throws DataFileException
        Populates (or reloads) the data file with the text of the given content
        Parameters:
        content - The text data to populate the DataFile with
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • readDataFile

        public void readDataFile​(java.io.InputStream dataFileStream,
                                 java.lang.String locationInfo)
                          throws DataFileException
        Loads (or reloads) the data file from the given stream
        Parameters:
        dataFileStream - A stream containing the text data for the data file
        locationInfo - Text information about where the data came from for exception messages
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • makeRecordIterator

        public RecordIterator makeRecordIterator​(java.net.URL fileUrl)
                                          throws DataFileException
        Make record iterator record iterator.
        Parameters:
        fileUrl - the file url
        Returns:
        the record iterator
        Throws:
        DataFileException - the data file exception
      • makeRecordIterator

        public RecordIterator makeRecordIterator​(java.io.InputStream dataFileStream,
                                                 java.lang.String locationInfo)
                                          throws DataFileException
        Make record iterator record iterator.
        Parameters:
        dataFileStream - the data file stream
        locationInfo - the location info
        Returns:
        the record iterator
        Throws:
        DataFileException - the data file exception
      • writeDataFile

        public void writeDataFile​(java.lang.String filename)
                           throws DataFileException
        Writes the records in this DataFile object to a text data file
        Parameters:
        filename - The filename to put the data into
        Throws:
        DataFileException - Exception thrown for various errors, generally has a nested exception
      • writeDataFile

        public java.lang.String writeDataFile()
                                       throws DataFileException
        Returns the records in this DataFile object as a plain text data file content
        Returns:
        A String containing what would go into a data file as plain text
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • writeDataFile

        public void writeDataFile​(java.io.OutputStream outStream)
                           throws DataFileException
        Writes the records in this DataFile object to the given OutputStream
        Parameters:
        outStream - The Stream to put the data into
        Throws:
        DataFileException - Exception thown for various errors, generally has a nested exception
      • writeRecords

        protected void writeRecords​(java.io.OutputStream outStream,
                                    java.util.List<Record> records)
                             throws DataFileException
        Write records.
        Parameters:
        outStream - the out stream
        records - the records
        Throws:
        DataFileException - the data file exception