Package eu.simuline.octave.io
Class OctaveIO
- java.lang.Object
-
- eu.simuline.octave.io.OctaveIO
-
public final class OctaveIO extends Object
The object controlling IO of Octave data ofoctaveExec. The basic operations are to-
set a map of variable names to their values
via
set(Map)(no setting of a single value), -
get the value for a variable name via
get(String), -
check whether a variable with a given name exists
via
existsVar(String).
-
readerReadLine(BufferedReader)reads a line -
read(BufferedReader)reads an object -
readWithName(BufferedReader)yields a singleton map name-->object, where name is the name of a variable -
readWithName(String)yields a singleton map name-->object, as above but reading from a string.
-
write(Writer, OctaveObject)write(Writer, String, OctaveObject) toText(String, OctaveObject) toText(OctaveObject)
-
set a map of variable names to their values
via
-
-
Field Summary
Fields Modifier and Type Field Description private static StringGLOBALprivate static StringNAMEprivate OctaveExecoctaveExecprivate static StringTYPE
-
Constructor Summary
Constructors Constructor Description OctaveIO(OctaveExec octaveExec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanexistsVar(String name)Returns whether the variablenameexists.OctaveObjectget(String name)Gets the value of the variablenameor null if this variable does not exist according toexistsVar(String).static OctaveObjectread(BufferedReader reader)Read a single object from Reader.static StringreaderReadLine(BufferedReader reader)Reads a line fromreaderinto a string if possible.static Map<String,OctaveObject>readWithName(BufferedReader reader)Read a single variable - object pair from Reader.static Map<String,OctaveObject>readWithName(String input)Read a single object from String, it is an error if there is data left after the object.voidset(Map<String,OctaveObject> name2val)Sets the variables named as keys inname2valto objects given by the mapped values.static StringtoText(OctaveObject octValue)Returns as a string how theOctaveObjectoctaveType(****bad name) is written without variable, i.e. with variable"ans".static StringtoText(String name, OctaveObject octValue)Returns as a string how the variablenameand theOctaveObjectoctaveType(****bad name) are written.static voidwrite(Writer writer, String name, OctaveObject octValue)ER: Writes the namenameand theOctaveObjectoctValueto the writerwriterusingwrite(Writer, OctaveObject).static <T extends OctaveObject>
voidwrite(Writer writer, T octValue)static voidwriterWriteLine(Writer writer, String strWithNl)Writes a line given bystrWithNltowriterif possible.
-
-
-
Field Detail
-
GLOBAL
private static final String GLOBAL
- See Also:
- Constant Field Values
-
TYPE
private static final String TYPE
- See Also:
- Constant Field Values
-
NAME
private static final String NAME
- See Also:
- Constant Field Values
-
octaveExec
private final OctaveExec octaveExec
-
-
Constructor Detail
-
OctaveIO
public OctaveIO(OctaveExec octaveExec)
- Parameters:
octaveExec-
-
-
Method Detail
-
set
public void set(Map<String,OctaveObject> name2val)
Sets the variables named as keys inname2valto objects given by the mapped values.- Parameters:
name2val- a mapping from variable names to according objects.
-
get
public OctaveObject get(String name)
Gets the value of the variablenameor null if this variable does not exist according toexistsVar(String).- Parameters:
name- the name of a variable- Returns:
- the value of the variable
namefrom octave ornullif the variable does not exist. - Throws:
OctaveClassCastException- if the value can not be cast to T
-
existsVar
private boolean existsVar(String name)
Returns whether the variablenameexists.- Parameters:
name- the name of a variable- Returns:
- whether the variable
nameexists.
-
readerReadLine
public static String readerReadLine(BufferedReader reader)
Reads a line fromreaderinto a string if possible. Returns null at the end of the stream and throws an exception in case of io problems.- Parameters:
reader- the reader to read a line from.- Returns:
- next line from
reader,nullat end of stream - Throws:
OctaveIOException- in case of IOException reading fromreader.
-
read
public static OctaveObject read(BufferedReader reader)
Read a single object from Reader. The first line read determines the type of object and the rest of reading is delegated to the OctaveDataReader associated with that type given byOctaveDataReader.getOctaveDataReader(String).- Parameters:
reader- a reader starting with first line, i.e.TYPE[global ]typeglobalis optional and type is the type of the object to be read.- Returns:
- OctaveObject read from Reader
- Throws:
OctaveParseException- **** appropriate type? if the type read before is not registered and so there is no appropriate reader.
-
readWithName
public static Map<String,OctaveObject> readWithName(BufferedReader reader)
Read a single variable - object pair from Reader. The variable is given by its name.- Parameters:
reader- a reader starting with first line, where name is the name of the variable. the following lines represent the object stored in that variable.NAMEname- Returns:
- a singleton map with the name of a variable and object stored therein.
-
readWithName
public static Map<String,OctaveObject> readWithName(String input)
Read a single object from String, it is an error if there is data left after the object.- Parameters:
input-- Returns:
- a singleton map with the name and object
- Throws:
OctaveParseException- if there is data left after the object is read
-
writerWriteLine
public static void writerWriteLine(Writer writer, String strWithNl)
Writes a line given bystrWithNltowriterif possible.- Parameters:
writer-strWithNl-- Throws:
OctaveIOException- in case of IOException writing towriter.
-
write
public static <T extends OctaveObject> void write(Writer writer, T octValue) throws IOException
ER: Writes theOctaveObjectoctaveType(****bad name) to the writerwriter. To that end, fetch anOctaveDataWriterof the appropriate type given byoctaveTypeand use this writer to writeoctaveTypeontowriter.- Type Parameters:
T- the type ofOctaveObjectto be written.- Parameters:
writer- the writer to write the objectoctValueonto.octValue- the object to write towriter.- Throws:
OctaveParseException- **** appropriate type? if the type ofoctValueis not registered and so there is no appropriate writer.IOException- if the process of writing fails.
-
write
public static void write(Writer writer, String name, OctaveObject octValue) throws IOException
ER: Writes the namenameand theOctaveObjectoctValueto the writerwriterusingwrite(Writer, OctaveObject).- Parameters:
writer- the writer to write the objectoctaveTypeonto.name- the name, **** of a variableoctValue- the object to write towriter.- Throws:
OctaveParseException- **** appropriate type? if the type ofoctaveTypeis not registered and so there is no appropriate writer.IOException- if the process of writing fails.
-
toText
public static String toText(String name, OctaveObject octValue)
Returns as a string how the variablenameand theOctaveObjectoctaveType(****bad name) are written.- Parameters:
name- the name, **** of a variableoctValue- the object to write towriter.- Returns:
- The result from saving the value octaveType in octave -text format
-
toText
public static String toText(OctaveObject octValue)
Returns as a string how theOctaveObjectoctaveType(****bad name) is written without variable, i.e. with variable"ans".- Parameters:
octValue-- Returns:
- toText("ans", octValue)
-
-