ch.javasoft.jsmat
Class MatWriter<D extends DataOutput>

java.lang.Object
  extended by ch.javasoft.jsmat.MatWriter<D>
Type Parameters:
D - output type
Direct Known Subclasses:
MatFileWriter, MatOutputStreamWriter

public abstract class MatWriter<D extends DataOutput>
extends Object

MatWriter is an abstract superclass for different writers producing .mat formatted output.

Common subclasses are


Field Summary
protected  ReservedWriter mReservedWriter
           
 
Constructor Summary
MatWriter(D out)
           
 
Method Summary
protected  void checkNoReservedWriter()
          Throws an io exception if an open reserved writer exists
abstract  void close()
          Close the target.
 ReservedComplexWriter createReservedWriter(String name, MatReservedComplex reserved)
          Creates a writer for the given reserved variable.
<A> ReservedMatrixWriter<A>
createReservedWriter(String name, MatReservedMatrix<A> reserved)
          Creates a writer for the given reserved variable.
protected abstract  VariableWriter createVariableWriter()
          Creates a writer for variable output.
protected abstract  void initDataOutput(D dataOutput)
          StackTrace called in the constructor before anything is written to the data output.
 void write(Map<String,? extends MatAllocated> variables)
          Write the given matrices.
 void write(String name, MatAllocated variable)
          Write the given matrix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mReservedWriter

protected ReservedWriter mReservedWriter
Constructor Detail

MatWriter

public MatWriter(D out)
          throws IOException
Throws:
IOException
Method Detail

initDataOutput

protected abstract void initDataOutput(D dataOutput)
                                throws IOException
StackTrace called in the constructor before anything is written to the data output. For instance, the file could be opened/cleared here.

Parameters:
dataOutput - the data output object to initialize
Throws:
IOException

createVariableWriter

protected abstract VariableWriter createVariableWriter()
                                                throws IOException
Creates a writer for variable output. Variables are written compressed, which needs some initialization executed when VariableWriter.open() is called. The same structures must be released again after writing the variable data, which is done in VariableWriter.close().

Throws:
IOException

write

public void write(String name,
                  MatAllocated variable)
           throws IOException
Write the given matrix

Parameters:
name - name of the matrix
variable - the variable containing the data
Throws:
IOException - if any io exception occurs

checkNoReservedWriter

protected void checkNoReservedWriter()
                              throws IOException
Throws an io exception if an open reserved writer exists

Throws:
IOException

createReservedWriter

public ReservedComplexWriter createReservedWriter(String name,
                                                  MatReservedComplex reserved)
                                           throws IOException
Creates a writer for the given reserved variable. Reserved variables are placeholders for data. The size of the data is already known, but to reduce memory demands, the values are not allocated yet. The reserved writer allows appending data piecewise. It must be closed to complete the data output process for the given reserved variable.

Parameters:
name - The matlab name of the variable
reserved - The variable reserving space for data
Returns:
Writer to stream out data piecewise. Has to be closed to complete the data output process.
Throws:
IOException - If another unclosed reserved writer exists, or if any other io exception occurs

createReservedWriter

public <A> ReservedMatrixWriter<A> createReservedWriter(String name,
                                                        MatReservedMatrix<A> reserved)
                                             throws IOException
Creates a writer for the given reserved variable. Reserved variables are placeholders for data. The size of the data is already known, but to reduce memory demands, the values are not allocated yet. The reserved writer allows appending data piecewise. It must be closed to complete the data output process for the given reserved variable.

Type Parameters:
A - The java data type, defined by the reserved variable
Parameters:
name - The matlab name of the variable
reserved - The variable reserving space for data
Returns:
Writer to stream out data piecewise. Has to be closed to complete the data output process.
Throws:
IOException - If another unclosed reserved writer exists, or if any other io exception occurs

write

public void write(Map<String,? extends MatAllocated> variables)
           throws IOException
Write the given matrices. It is recommended to use LinkedHashMap in order to preserve the order of the variables, or TreeMap to sort the variables lexicographically.

The method write(String, MatAllocated) is invoked with every name/value pair in matrices.

Parameters:
variables - a map containing name/variable pairs to be written
Throws:
IOException - if any io exception occurs

close

public abstract void close()
                    throws IOException
Close the target. For instance, the underlying file or output stream could be closed here.

Throws:
IOException - if any io exception occurs