public class OFStream extends OStream
ofstream
.
The C++ ofstream
('output file stream') provides an
interface for writing data to files as output streams. This class,
OFStream
, wraps the C++ ofstream
and provides an OStream
interface to it. The file to be associated with the stream can be
specified as a parameter to the constructors in this class.
This class may be useful because some libSBML methods accept an argument
for indicating where to send text string output. An example is the
SBMLDocument.printErrors(OStream stream)
method. The methods use C++ style streams
and not Java stream objects. The OStream
object exists to bridge the
Java and underlying native implementation. It is a simple wrapper
around the underlying stream object and provides a few basic methods for
manipulating it.
Constructor and Description |
---|
OFStream(String filename)
Creates a new
OFStream object for a file. |
OFStream(String filename,
boolean is_append)
Creates a new
OFStream object for a file. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the file currently associated with this stream object.
|
void |
delete()
Explicitly deletes the underlying native object.
|
boolean |
is_open()
Returns
true if this stream object is currently
associated with a file. |
void |
open(String filename)
Opens a file and associates this stream object with it.
|
void |
open(String filename,
boolean is_append)
Opens a file and associates this stream object with it.
|
endl, get_ostream
public OFStream(String filename)
OFStream
object for a file.
This opens the given file filename
with the is_append
flag
(default is false
), and creates an OFStream
object
instance that associates the file's content with an OStream
object.
filename
- the name of the file to openis_append
- whether to open the file for appending (default:
false
, meaning overwrite the content instead)
public OFStream(String filename, boolean is_append)
OFStream
object for a file.
This opens the given file filename
with the is_append
flag
(default is false
), and creates an OFStream
object
instance that associates the file's content with an OStream
object.
filename
- the name of the file to openis_append
- whether to open the file for appending (default:
false
, meaning overwrite the content instead)
public void close()
public void delete()
In general, application software will not need to call this method directly. The Java language binding for libSBML is implemented as a language wrapper that provides a Java interface to libSBML's underlying C++/C code. Some of the Java methods return objects that are linked to objects created not by Java code, but by C++ code. The Java objects wrapped around them will be deleted when the garbage collector invokes the corresponding C++ finalize()
methods for the objects. The finalize()
methods in turn call the OFStream.delete()
method on the libSBML object.
This method is exposed in case calling programs want to ensure that the underlying object is freed immediately, and not at some arbitrary time determined by the Java garbage collector. In normal usage, callers do not need to invoke OFStream.delete()
themselves.
public boolean is_open()
true
if this stream object is currently
associated with a file.
true
if the stream object is currently
associated with a file, false
otherwisepublic void open(String filename)
This method opens a given file filename
with the given
is_append
flag (whose default value is false
),
and associates this stream object with the file's content.
filename
- the name of the file to openis_append
- whether to open the file for appending (default:
false
, meaning overwrite the content instead)
public void open(String filename, boolean is_append)
This method opens a given file filename
with the given
is_append
flag (whose default value is false
),
and associates this stream object with the file's content.
filename
- the name of the file to openis_append
- whether to open the file for appending (default:
false
, meaning overwrite the content instead)