Package jahuwaldt.js.datareader
Class TabDataReader
- java.lang.Object
-
- jahuwaldt.js.datareader.TabDataReader
-
- All Implemented Interfaces:
DataReader
,java.lang.Comparable<DataReader>
public class TabDataReader extends java.lang.Object implements DataReader
This class translates data between a list of DataSet data structures and a stream containing tab, space, or comma delimited columns of array data with a single line header indicating the names of the parameters and an optional second line indicating the units of each parameter. Only arrays can be read or written to this format. They all must be the same length (in the same case).Modified by: Joseph A. Huwaldt
- Version:
- March 21, 2017
- Author:
- Joseph A. Huwaldt, Date: May 19, 2003
-
-
Constructor Summary
Constructors Constructor Description TabDataReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
canReadData(java.lang.String pathName, java.io.BufferedInputStream input)
Method that determines if this reader can read data from the specified input stream.boolean
canWriteData()
Returns true.int
compareTo(DataReader o)
Compares this object with the specified object for order based on thetoString().compareTo(o.toString())
method.java.lang.String
getExtension()
Returns the preferred file extension (not including the ".") for files of this DataReader's type.java.util.List<DataSet>
read(java.lang.String pathName, java.io.InputStream input)
Method that reads in tab, space or comma delimited array data from the specified input stream and returns that data as a list ofDataSet
objects.java.util.List<DataSet>
selectDataForSaving(java.awt.Frame parent, java.util.List<DataSet> data)
The Tabbed Array format can save only a single case of arrays.void
setDefaultSetName(java.lang.CharSequence name)
Sets the default set name to use.java.lang.String
toString()
Returns a string representation of the object.void
write(java.io.OutputStream output, java.util.List<DataSet> data)
Method that writes out all the data stored in the specified list ofDataSet
objects to the specified output stream in tabbed array format.
-
-
-
Field Detail
-
NO_UNITS
public static final java.lang.String NO_UNITS
- See Also:
- Constant Field Values
-
EXTENSION
public static final java.lang.String EXTENSION
-
-
Constructor Detail
-
TabDataReader
public TabDataReader()
-
-
Method Detail
-
toString
public java.lang.String toString()
Returns a string representation of the object. This will return a brief description of the format read by this reader.- Overrides:
toString
in classjava.lang.Object
-
getExtension
public java.lang.String getExtension()
Returns the preferred file extension (not including the ".") for files of this DataReader's type.- Specified by:
getExtension
in interfaceDataReader
- Returns:
- The preferred file extension for this file's type.
-
compareTo
public int compareTo(DataReader o)
Compares this object with the specified object for order based on thetoString().compareTo(o.toString())
method. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfacejava.lang.Comparable<DataReader>
-
canReadData
public int canReadData(java.lang.String pathName, java.io.BufferedInputStream input) throws java.io.IOException
Method that determines if this reader can read data from the specified input stream.- Specified by:
canReadData
in interfaceDataReader
- Parameters:
pathName
- The path to the file to be read.input
- An input stream containing the data to be read. Any methods that read from this stream must first set a mark and then reset back to that mark before the method returns (even if it returns with an exception).- Returns:
- DataReader.NO if the file is not recognized at all or DataReader.MAYBE if the file has an appropriate extension.
- Throws:
java.io.IOException
- If the input stream could not be read.
-
canWriteData
public boolean canWriteData()
Returns true. This class can write data to a tabbed arrays formatted file.- Specified by:
canWriteData
in interfaceDataReader
- Returns:
- Always returns true.
-
selectDataForSaving
public java.util.List<DataSet> selectDataForSaving(java.awt.Frame parent, java.util.List<DataSet> data)
The Tabbed Array format can save only a single case of arrays.- Specified by:
selectDataForSaving
in interfaceDataReader
- Parameters:
parent
- Determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used.data
- The input data set that is to be selected for saving.- Returns:
- A list of DataSet objects containing the selected data to be saved. Could return null if the user selects nothing.
-
read
public java.util.List<DataSet> read(java.lang.String pathName, java.io.InputStream input) throws java.io.IOException
Method that reads in tab, space or comma delimited array data from the specified input stream and returns that data as a list ofDataSet
objects.- Specified by:
read
in interfaceDataReader
- Parameters:
pathName
- The path to the file to be read.input
- An input stream containing the tab, space or comma delimited array data.- Returns:
- A list of DataSet objects that contains the data read in from the specified stream (will contain a single data set which will contain a single case with ArrayParam objects for each column).
- Throws:
java.io.IOException
- If there is a problem reading the specified stream.
-
write
public void write(java.io.OutputStream output, java.util.List<DataSet> data) throws java.io.IOException
Method that writes out all the data stored in the specified list ofDataSet
objects to the specified output stream in tabbed array format. Only the 1st case in the 1st data set in the specified list is written out since the tabbed array format does not support multiple cases. Only arrays are written out since the tabbed array format does not support scalars or text notes.- Specified by:
write
in interfaceDataReader
- Parameters:
output
- The output stream to which the data is to be written.data
- A list ofDataSet
objects containing data to be written out. Only the 1st case in the 1st data set in the list is written out.- Throws:
java.io.IOException
- If there is a problem writing to the specified stream.
-
setDefaultSetName
public void setDefaultSetName(java.lang.CharSequence name)
Sets the default set name to use.- Specified by:
setDefaultSetName
in interfaceDataReader
- Parameters:
name
- The name to use as the default set name.
-
-