ch.javasoft.jsmat.primitive
Class MatPrimitive

java.lang.Object
  extended by ch.javasoft.jsmat.primitive.MatPrimitive
Direct Known Subclasses:
MatDouble, MatInt16, MatInt32, MatInt64, MatInt8, MatSingle, MatUInt16, MatUInt32, MatUInt64, MatUInt8, MatUtf16, MatUtf32, MatUtf8

public abstract class MatPrimitive
extends Object

MatPrimitive is the abstract superclass for all primitive matlab types. These classes are used to read and write raw data. Typically, data consists of a type flag (4 bytes), the size of the block (4 bytes), the raw data block and some padding bytes if needed.


Constructor Summary
MatPrimitive(MatType type)
          Constructor with type constant
 
Method Summary
abstract  int getArrayLength()
           
 int getRawDataSize()
           
 int getSize()
           
protected  int getUnitSize()
           
 void write(DataOutput out)
          Writes the data block: type, raw size, raw data, padding (this order).
protected abstract  void writeBody(DataOutput out)
          Writes the raw data block, without padding, type and size information
static void writeEnd(MatType mType, DataOutput out, int rawDataSize)
           
static void writeStart(MatType mType, DataOutput out, int rawDataSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatPrimitive

public MatPrimitive(MatType type)
Constructor with type constant

Parameters:
type - the type constant
Method Detail

getRawDataSize

public int getRawDataSize()
Returns:
size of raw data (bytes) excluding padding, type(4) and size(4), that is getUnitSize() times getArrayLength()

getArrayLength

public abstract int getArrayLength()
Returns:
the logical data length, that is getRawDataSize() divided by getUnitSize(). this is usually the length of the array storing the data in java

writeStart

public static void writeStart(MatType mType,
                              DataOutput out,
                              int rawDataSize)
                       throws IOException
Throws:
IOException

writeBody

protected abstract void writeBody(DataOutput out)
                           throws IOException
Writes the raw data block, without padding, type and size information

Parameters:
out - the data output to write to
Throws:
IOException - if any io exception occurs

writeEnd

public static void writeEnd(MatType mType,
                            DataOutput out,
                            int rawDataSize)
                     throws IOException
Throws:
IOException

getSize

public int getSize()
Returns:
the total size of this data block, including type, size and padding (if any)

write

public void write(DataOutput out)
           throws IOException
Writes the data block: type, raw size, raw data, padding (this order). To write the raw data, which is type specific (implemented in subclasses), writeBody(DataOutput) is called.

Equivalent to calling

  writeStart(out);
        writeBody(out);
        writeEnd(out);
 

Parameters:
out - the data output to write to
Throws:
IOException - if any io exception occurs

getUnitSize

protected int getUnitSize()
Returns:
the unit size, that is, the number of bytes used to store one value of this type. see MatType.size