SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.util.io.BinaryDataWriter Class Reference

Binary data writer. More...

Inheritance diagram for umontreal.ssj.util.io.BinaryDataWriter:
umontreal.ssj.util.io.AbstractDataWriter umontreal.ssj.util.io.DataWriter

Public Member Functions

 BinaryDataWriter (String filename, boolean append) throws IOException
 Data will be output to the file with the specified name.
 BinaryDataWriter (File file, boolean append) throws IOException
 Data will be output to the specified file.
 BinaryDataWriter (String filename) throws IOException
 Truncates any existing file with the specified name.
 BinaryDataWriter (File file) throws IOException
 Truncates any existing file with the specified name.
 BinaryDataWriter (OutputStream outputStream) throws IOException
 Constructor.
Writing atomic data @{
void write (String label, String s) throws IOException
 Writes an atomic string field.
void write (String label, int a) throws IOException
 Writes an atomic 32-bit integer (big endian).
void write (String label, float a) throws IOException
 Writes an atomic 32-bit float (big endian).
void write (String label, double a) throws IOException
 Writes an atomic 64-bit double (big endian).
Writing one-dimensional arrays @{
void write (String label, String[] a, int n) throws IOException
 Writes the first n elements of a one-dimensional array of strings.
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).
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).
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).
Writing two-dimensional arrays @{
void write (String label, String[][] a) throws IOException
 Writes a two-dimensional array of strings.
void write (String label, int[][] a) throws IOException
 Writes a two-dimensional array of 32-bit integers (big endian).
void write (String label, float[][] a) throws IOException
 Writes a two-dimensional array of 32-bit floats (big endian).
void write (String label, double[][] a) throws IOException
 Writes a two-dimensional array of 64-bit doubles (big endian).
Other methods @{
void close () throws IOException
 Flushes any pending data and closes the file.
Public Member Functions inherited from umontreal.ssj.util.io.AbstractDataWriter
void write (String label, String[] a) throws IOException
 Writes a one-dimensional array of strings.
void write (String label, int[] a) throws IOException
 Writes a one-dimensional array of 32-bit integers (big endian).
void write (String label, float[] a) throws IOException
 Writes a one-dimensional array of 32-bit floats (big endian).
void write (String label, double[] a) throws IOException
 Writes a one-dimensional array of 64-bit doubles (big endian).
Public Member Functions inherited from umontreal.ssj.util.io.DataWriter

Static Public Attributes

Fields @{
static final byte TYPECHAR_LABEL = '|'
 Field-type symbol indicating a label (it more accurately a field separator symbol).
static final byte TYPECHAR_STRING = 'S'
 Field-type symbol indicating String data.
static final byte TYPECHAR_INTEGER = 'i'
 Field-type symbol indicating int data.
static final byte TYPECHAR_FLOAT = 'f'
 Field-type symbol indicating float data.
static final byte TYPECHAR_DOUBLE = 'd'
 Field-type symbol indicating double data.

Protected Member Functions

void writeStringData (String s) throws IOException
 Utility method to write string data.
void writeLabel (String label) throws IOException
 Starts a new field by writing its label.

Detailed Description

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:

  • Field label:

    • Pipe character (|)
    • Label length (32-bit integer, big endian)
    • Label string (array of bytes of the specified length)
  • Field type (byte):

    • i (32-bit integer)
    • f (32-bit float)
    • d (64-bit double)
    • S (string)
  • Number of dimensions (8-bit integer)
  • Dimensions (array of 32-bit integers, big endian)
  • Field data (in the specified format, big endian)

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

A string field is stored in the following format:

  • String length (32-bit integer)
  • Array of bytes of the specified length

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).

 Provide links for the import modules.

 <div class="SSJ-bigskip"></div>

Definition at line 79 of file BinaryDataWriter.java.

Constructor & Destructor Documentation

◆ BinaryDataWriter() [1/5]

umontreal.ssj.util.io.BinaryDataWriter.BinaryDataWriter ( String filename,
boolean append ) throws IOException

Data will be output to the file with the specified name.

Parameters
filenamename of the file to be created or appended to
appendan existing file with the specified name will be appended to if true or truncated if false

Definition at line 147 of file BinaryDataWriter.java.

◆ BinaryDataWriter() [2/5]

umontreal.ssj.util.io.BinaryDataWriter.BinaryDataWriter ( File file,
boolean append ) throws IOException

Data will be output to the specified file.

Parameters
filefile to be created or appended to
appendan existing file with the specified name will be appended to if true or truncated if false

Definition at line 158 of file BinaryDataWriter.java.

◆ BinaryDataWriter() [3/5]

umontreal.ssj.util.io.BinaryDataWriter.BinaryDataWriter ( String filename) throws IOException

Truncates any existing file with the specified name.

Parameters
filenamename of the file to be created

Definition at line 167 of file BinaryDataWriter.java.

◆ BinaryDataWriter() [4/5]

umontreal.ssj.util.io.BinaryDataWriter.BinaryDataWriter ( File file) throws IOException

Truncates any existing file with the specified name.

Parameters
filefile to be created

Definition at line 176 of file BinaryDataWriter.java.

◆ BinaryDataWriter() [5/5]

umontreal.ssj.util.io.BinaryDataWriter.BinaryDataWriter ( OutputStream outputStream) throws IOException

Constructor.

Parameters
outputStreamoutput stream to write to

Definition at line 185 of file BinaryDataWriter.java.

Member Function Documentation

◆ close()

void umontreal.ssj.util.io.BinaryDataWriter.close ( ) throws IOException

Flushes any pending data and closes the file.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 376 of file BinaryDataWriter.java.

◆ write() [1/12]

void umontreal.ssj.util.io.BinaryDataWriter.write ( String label,
double a ) throws IOException

Writes an atomic 64-bit double (big endian).

Writes an anonymous field if label is null.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 230 of file BinaryDataWriter.java.

◆ write() [2/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 288 of file BinaryDataWriter.java.

◆ write() [3/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 354 of file BinaryDataWriter.java.

◆ write() [4/12]

void umontreal.ssj.util.io.BinaryDataWriter.write ( String label,
float a ) throws IOException

Writes an atomic 32-bit float (big endian).

Writes an anonymous field if label is null.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 219 of file BinaryDataWriter.java.

◆ write() [5/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 275 of file BinaryDataWriter.java.

◆ write() [6/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 339 of file BinaryDataWriter.java.

◆ write() [7/12]

void umontreal.ssj.util.io.BinaryDataWriter.write ( String label,
int a ) throws IOException

Writes an atomic 32-bit integer (big endian).

Writes an anonymous field if label is null.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 208 of file BinaryDataWriter.java.

◆ write() [8/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 262 of file BinaryDataWriter.java.

◆ write() [9/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 324 of file BinaryDataWriter.java.

◆ write() [10/12]

void umontreal.ssj.util.io.BinaryDataWriter.write ( String label,
String s ) throws IOException

Writes an atomic string field.

Writes an anonymous field if label is null.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 197 of file BinaryDataWriter.java.

◆ write() [11/12]

void umontreal.ssj.util.io.BinaryDataWriter.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.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 249 of file BinaryDataWriter.java.

◆ write() [12/12]

void umontreal.ssj.util.io.BinaryDataWriter.write ( String label,
String a[][] ) throws IOException

Writes a two-dimensional array of strings.

Writes an anonymous field if label is null.

Implements umontreal.ssj.util.io.DataWriter.

Definition at line 309 of file BinaryDataWriter.java.

◆ writeLabel()

void umontreal.ssj.util.io.BinaryDataWriter.writeLabel ( String label) throws IOException
protected

Starts a new field by writing its label.

Parameters
labelname of the field (can be null)

Definition at line 101 of file BinaryDataWriter.java.

◆ writeStringData()

void umontreal.ssj.util.io.BinaryDataWriter.writeStringData ( String s) throws IOException
protected

Utility method to write string data.

Definition at line 86 of file BinaryDataWriter.java.

Member Data Documentation

◆ TYPECHAR_DOUBLE

final byte umontreal.ssj.util.io.BinaryDataWriter.TYPECHAR_DOUBLE = 'd'
static

Field-type symbol indicating double data.

Definition at line 134 of file BinaryDataWriter.java.

◆ TYPECHAR_FLOAT

final byte umontreal.ssj.util.io.BinaryDataWriter.TYPECHAR_FLOAT = 'f'
static

Field-type symbol indicating float data.

Definition at line 129 of file BinaryDataWriter.java.

◆ TYPECHAR_INTEGER

final byte umontreal.ssj.util.io.BinaryDataWriter.TYPECHAR_INTEGER = 'i'
static

Field-type symbol indicating int data.

Definition at line 124 of file BinaryDataWriter.java.

◆ TYPECHAR_LABEL

final byte umontreal.ssj.util.io.BinaryDataWriter.TYPECHAR_LABEL = '|'
static

Field-type symbol indicating a label (it more accurately a field separator symbol).

Definition at line 114 of file BinaryDataWriter.java.

◆ TYPECHAR_STRING

final byte umontreal.ssj.util.io.BinaryDataWriter.TYPECHAR_STRING = 'S'
static

Field-type symbol indicating String data.

Definition at line 119 of file BinaryDataWriter.java.


The documentation for this class was generated from the following file: