SSJ
V. 2.6.2.

umontreal.iro.lecuyer.util.io
Class BinaryDataWriter

java.lang.Object
  extended by umontreal.iro.lecuyer.util.io.AbstractDataWriter
      extended by umontreal.iro.lecuyer.util.io.BinaryDataWriter
All Implemented Interfaces:
DataWriter

public class BinaryDataWriter
extends AbstractDataWriter

Binary data writer.

Stores a sequence of fields in binary file, which can be either atoms or arrays, each of which having the following format:

In the case of an atomic field, the number of dimensions is set to zero.

A string field is stored in the following format:

Also supports anonymous fields (fields with an empty label).

Arrays up to two dimensions are supported.

Modules for reading data exported with this class are available in Java (BinaryDataReader), Matlab and Python (numpy).


Field Summary
static byte TYPECHAR_DOUBLE
          Field-type symbol indicating double data.
static byte TYPECHAR_FLOAT
          Field-type symbol indicating float data.
static byte TYPECHAR_INTEGER
          Field-type symbol indicating int data.
static byte TYPECHAR_LABEL
          Field-type symbol indicating a label (it more accurately a field separator symbol).
static byte TYPECHAR_STRING
          Field-type symbol indicating String data.
 
Constructor Summary
BinaryDataWriter(File file)
          Truncates any existing file with the specified name.
BinaryDataWriter(File file, boolean append)
          Data will be output to the specified file.
BinaryDataWriter(OutputStream outputStream)
          Constructor.
BinaryDataWriter(String filename)
          Truncates any existing file with the specified name.
BinaryDataWriter(String filename, boolean append)
          Data will be output to the file with the specified name.
 
Method Summary
 void close()
          Flushes any pending data and closes the file.
 void write(String label, double a)
          Writes an atomic 64-bit double (big endian).
 void write(String label, double[][] a)
          Writes a two-dimensional array of 64-bit doubles (big endian).
 void write(String label, double[] a, int n)
          Writes the first n elements of a one-dimensional array of 64-bit doubles (big endian).
 void write(String label, float a)
          Writes an atomic 32-bit float (big endian).
 void write(String label, float[][] a)
          Writes a two-dimensional array of 32-bit floats (big endian).
 void write(String label, float[] a, int n)
          Writes the first n elements of a one-dimensional array of 32-bit floats (big endian).
 void write(String label, int a)
          Writes an atomic 32-bit integer (big endian).
 void write(String label, int[][] a)
          Writes a two-dimensional array of 32-bit integers (big endian).
 void write(String label, int[] a, int n)
          Writes the first n elements of a one-dimensional array of 32-bit integers (big endian).
 void write(String label, String s)
          Writes an atomic string field.
 void write(String label, String[][] a)
          Writes a two-dimensional array of strings.
 void write(String label, String[] a, int n)
          Writes the first n elements of a one-dimensional array of strings.
 
Methods inherited from class umontreal.iro.lecuyer.util.io.AbstractDataWriter
write, write, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPECHAR_LABEL

public static final byte TYPECHAR_LABEL
Field-type symbol indicating a label (it more accurately a field separator symbol).

See Also:
Constant Field Values

TYPECHAR_STRING

public static final byte TYPECHAR_STRING
Field-type symbol indicating String data.

See Also:
Constant Field Values

TYPECHAR_INTEGER

public static final byte TYPECHAR_INTEGER
Field-type symbol indicating int data.

See Also:
Constant Field Values

TYPECHAR_FLOAT

public static final byte TYPECHAR_FLOAT
Field-type symbol indicating float data.

See Also:
Constant Field Values

TYPECHAR_DOUBLE

public static final byte TYPECHAR_DOUBLE
Field-type symbol indicating double data.

See Also:
Constant Field Values
Constructor Detail

BinaryDataWriter

public BinaryDataWriter(String filename,
                        boolean append)
                 throws IOException
Data will be output to the file with the specified name.

Parameters:
filename - name of the file to be created or appended to
append - an existing file with the specified name will be appended to if true or truncated if false
Throws:
IOException

BinaryDataWriter

public BinaryDataWriter(File file,
                        boolean append)
                 throws IOException
Data will be output to the specified file.

Parameters:
file - file to be created or appended to
append - an existing file with the specified name will be appended to if true or truncated if false
Throws:
IOException

BinaryDataWriter

public BinaryDataWriter(String filename)
                 throws IOException
Truncates any existing file with the specified name.

Parameters:
filename - name of the file to be created
Throws:
IOException

BinaryDataWriter

public BinaryDataWriter(File file)
                 throws IOException
Truncates any existing file with the specified name.

Parameters:
file - file to be created
Throws:
IOException

BinaryDataWriter

public BinaryDataWriter(OutputStream outputStream)
                 throws IOException
Constructor.

Parameters:
outputStream - output stream to write to
Throws:
IOException
Method Detail

write

public void write(String label,
                  String s)
           throws IOException
Writes an atomic string field. Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  int a)
           throws IOException
Writes an atomic 32-bit integer (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  float a)
           throws IOException
Writes an atomic 32-bit float (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  double a)
           throws IOException
Writes an atomic 64-bit double (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  String[] a,
                  int n)
           throws IOException
Writes the first n elements of a one-dimensional array of strings. Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  int[] a,
                  int n)
           throws IOException
Writes the first n elements of a one-dimensional array of 32-bit integers (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  float[] a,
                  int n)
           throws IOException
Writes the first n elements of a one-dimensional array of 32-bit floats (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  double[] a,
                  int n)
           throws IOException
Writes the first n elements of a one-dimensional array of 64-bit doubles (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  String[][] a)
           throws IOException
Writes a two-dimensional array of strings. Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  int[][] a)
           throws IOException
Writes a two-dimensional array of 32-bit integers (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  float[][] a)
           throws IOException
Writes a two-dimensional array of 32-bit floats (big endian). Writes an anonymous field if label is null.

Throws:
IOException

write

public void write(String label,
                  double[][] a)
           throws IOException
Writes a two-dimensional array of 64-bit doubles (big endian). Writes an anonymous field if label is null.

Throws:
IOException

close

public void close()
           throws IOException
Flushes any pending data and closes the file.

Throws:
IOException

SSJ
V. 2.6.2.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.