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 String
GLOBAL
private static String
NAME
private OctaveExec
octaveExec
private static String
TYPE
-
Constructor Summary
Constructors Constructor Description OctaveIO(OctaveExec octaveExec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
existsVar(String name)
Returns whether the variablename
exists.OctaveObject
get(String name)
Gets the value of the variablename
or null if this variable does not exist according toexistsVar(String)
.static OctaveObject
read(BufferedReader reader)
Read a single object from Reader.static String
readerReadLine(BufferedReader reader)
Reads a line fromreader
into 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.void
set(Map<String,OctaveObject> name2val)
Sets the variables named as keys inname2val
to objects given by the mapped values.static String
toText(OctaveObject octValue)
Returns as a string how theOctaveObject
octaveType
(****bad name) is written without variable, i.e. with variable"ans"
.static String
toText(String name, OctaveObject octValue)
Returns as a string how the variablename
and theOctaveObject
octaveType
(****bad name) are written.static void
write(Writer writer, String name, OctaveObject octValue)
ER: Writes the namename
and theOctaveObject
octValue
to the writerwriter
usingwrite(Writer, OctaveObject)
.static <T extends OctaveObject>
voidwrite(Writer writer, T octValue)
static void
writerWriteLine(Writer writer, String strWithNl)
Writes a line given bystrWithNl
towriter
if 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 inname2val
to 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 variablename
or null if this variable does not exist according toexistsVar(String)
.- Parameters:
name
- the name of a variable- Returns:
- the value of the variable
name
from octave ornull
if 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 variablename
exists.- Parameters:
name
- the name of a variable- Returns:
- whether the variable
name
exists.
-
readerReadLine
public static String readerReadLine(BufferedReader reader)
Reads a line fromreader
into 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
,null
at 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 ]typeglobal
is 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.NAME
name- 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 bystrWithNl
towriter
if 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 theOctaveObject
octaveType
(****bad name) to the writerwriter
. To that end, fetch anOctaveDataWriter
of the appropriate type given byoctaveType
and use this writer to writeoctaveType
ontowriter
.- Type Parameters:
T
- the type ofOctaveObject
to be written.- Parameters:
writer
- the writer to write the objectoctValue
onto.octValue
- the object to write towriter
.- Throws:
OctaveParseException
- **** appropriate type? if the type ofoctValue
is 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 namename
and theOctaveObject
octValue
to the writerwriter
usingwrite(Writer, OctaveObject)
.- Parameters:
writer
- the writer to write the objectoctaveType
onto.name
- the name, **** of a variableoctValue
- the object to write towriter
.- Throws:
OctaveParseException
- **** appropriate type? if the type ofoctaveType
is 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 variablename
and theOctaveObject
octaveType
(****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 theOctaveObject
octaveType
(****bad name) is written without variable, i.e. with variable"ans"
.- Parameters:
octValue
-- Returns:
- toText("ans", octValue)
-
-