com.jstatcom.io
Class TSMatlabHandler

java.lang.Object
  extended by com.jstatcom.io.TSMatlabHandler
All Implemented Interfaces:
DataHandler

public final class TSMatlabHandler
extends java.lang.Object
implements DataHandler

Handles export and import of Matlab .mat files Level 5, according to the specification document "MAT-File Format Version 7" by Mathworks. This class should be used as a Singleton.

Author:
Markus Kraetzig

Constructor Summary
TSMatlabHandler()
           
 
Method Summary
 void exportData(java.io.File file, JSCData data, java.lang.String description)
          Exports data to a file in the format that the respective implementation of this interface handles.
 void exportTS(java.io.File file, TS[] ts, java.lang.String description)
          Exports time series to a file in the format that the respective implementation of this interface handles.
 JSCData getData(ImportTypes type)
          Gets the imported data according to an instance of TSImportTypes.
static TSMatlabHandler getInstance()
          Gets the singleton instance of this handler.
 boolean importData(java.io.File file)
          Initiates parsing of .mat Matlab file.
 void setTestMode(boolean noDialog)
          Sets this handler in test mode.
static int skipPaddingBytes(java.io.DataInputStream in, int padding, int bytes)
          Skips the bytes remaining to fill a padding -byte boundary after writing bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TSMatlabHandler

public TSMatlabHandler()
Method Detail

getInstance

public static TSMatlabHandler getInstance()
Gets the singleton instance of this handler.

Returns:
instance

importData

public boolean importData(java.io.File file)
Initiates parsing of .mat Matlab file.

Specified by:
importData in interface DataHandler
Parameters:
file - the file to read in
Returns:
true of import was ok, false if cancelled or erroneous
Throws:
java.lang.IllegalArgumentException - if (file == null || !file.isFile())
java.lang.RuntimeException - when file reading fails

skipPaddingBytes

public static int skipPaddingBytes(java.io.DataInputStream in,
                                   int padding,
                                   int bytes)
                            throws java.io.IOException
Skips the bytes remaining to fill a padding -byte boundary after writing bytes. It returns the number of skipped bytes.

Parameters:
in - stream to skip bytes on, can be null (then only skipped bytes are computed)
padding - boundary that must be filled
bytes - actual number of bytes that should be appended with padding bytes to fill the boundary
Returns:
number of bytes skipped
Throws:
java.io.IOException

getData

public JSCData getData(ImportTypes type)
Gets the imported data according to an instance of TSImportTypes.

Specified by:
getData in interface DataHandler
Parameters:
type - the elementtype of a time series dataset
Returns:
the data stored as JSCData
Throws:
java.lang.IllegalArgumentException - if (type == null)
java.lang.IllegalStateException - if nothing was imported before

exportTS

public void exportTS(java.io.File file,
                     TS[] ts,
                     java.lang.String description)
Description copied from interface: DataHandler
Exports time series to a file in the format that the respective implementation of this interface handles.

Implementation Note:
Not every handler implementation uses all information contained in a time series. For example, some handlers might not store the variable names, the date, and the description, because this may not be supported by the respective format.

Implementations of this method should throw unchecked exceptions in case of errors, which should be dealt with by the calling objects.

Specified by:
exportTS in interface DataHandler
Parameters:
file - the file to store the time series to
ts - array of time series to export
description - an optional dataset description that handler implementations might use

exportData

public void exportData(java.io.File file,
                       JSCData data,
                       java.lang.String description)
Description copied from interface: DataHandler
Exports data to a file in the format that the respective implementation of this interface handles. This method should throw an exception if the type of data is not suppported.

Implementations of this method should throw unchecked exceptions in case of errors, which should be dealt with by the calling objects.

Specified by:
exportData in interface DataHandler
Parameters:
file - the file to store the data to
data - the data object to store, must be supported
description - an optional description that handler implementations might use

setTestMode

public void setTestMode(boolean noDialog)
Sets this handler in test mode. No user dialog is shown, default values are used instead. This is helpful for running automated unit tests.

Parameters:
noDialog -