|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--norsys.netica.Streamer
An I/O handle to a file (for reading, writing, etc.).
See Also:
Net(Streamer) | Reads a net from the file identified by the passed stream | |
Net.write | Saves a net to a file with name specified by the passed stream | |
Net.writeCase | ||
Net.readCase |
Constructor Summary | |
Streamer(java.io.InputStream inStream,
Environ env)
Constructs a Norsys stream from a java.io.InputStream. |
|
Streamer(java.io.OutputStream outStream,
Environ env)
Constructs a Norsys stream from a java.io.OutputStream. |
|
Streamer(java.lang.String fileName)
Constructs a Norsys stream for the file with name filename, in the current default Environ (see getDefaultEnviron). |
|
Streamer(java.lang.String fileName,
Environ env)
Constructs a Norsys stream for the file with name filename. |
Method Summary | |
void |
close()
Deprecated. Use |
void |
finalize()
Releases the memory used by this Streamer. |
void |
flush()
For a Streamer constructed from a java.io.OutputStream (see Streamer(OutputStream)), this will transfer the current contents of the Streamer to the the java.io.OutputStream. |
Environ |
getEnviron()
Returns this Streamer's environment. |
java.lang.String |
getFileName()
Returns the name of the file (including full path) that this stream was last written to or read from, if any. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Streamer(java.lang.String fileName) throws NeticaException
String | filename | Path to the file to attach to this stream. |
public Streamer(java.lang.String fileName, Environ env) throws NeticaException
This stream can then be passed as an argument to methods which read or write a file, to identify which file to read or write.
When finished with the norsys.netica.Streamer created, delete it with finalize.
filename may contain a path to indicate in which directory the file is located. It should be a string in the format normally understood by the operating system currently being used (see the examples below).
filename does not have to indicate a file which already exists.
Parameters:
String | filename | Path to the file to attach to this stream. | ||
Environ | env | The Netica environment the stream is created in |
finalize | Delete it when done | |
Net.write | Saves a net to a file with name specified by the passed stream | |
Net.writeCase | ||
Net.readCase | ||
Net(Streamer) | Reads a net from the file identified by the passed stream |
net.write (new Streamer ("../nets/temp.dne"));Example #2:
See write// // Examples for UNIX / Linux // Streamer file = new Streamer ("temp3"); Streamer file = new Streamer ("/local/project1/configure.bn.txt"); Streamer file = new Streamer ("../nets/Umbrella.dne"); // // Examples for MS Windows // Streamer file = new Streamer ("temp3"); Streamer file = new Streamer ("C:local\\project1\\configur.txt"); Streamer file = new Streamer ("..\\nets\\Umbrella.dne"); // // Examples for MacOS // Streamer file = new Streamer ("temp3"); Streamer file = new Streamer ("local:project1:configure.bn.txt"); Streamer file = new Streamer ("::nets:Umbrella.dne");
public Streamer(java.io.InputStream inStream, Environ env) throws NeticaException
InputStream | inStream | Any java.io.InputStream. | ||
Environ | env | The Netica environment the stream is created in |
// read a net stored in a String String dneString = "// ~->[DNET-1]->~\nbnet test{};"; StringBufferInputStream sbis = new StringBufferInputStream (dneString); Net net5 = new Net (new Streamer (sbis, Environ.getDefaultEnviron()));
public Streamer(java.io.OutputStream outStream, Environ env) throws NeticaException
Note: The outStream is only guaranteed to be filled after calling flush or finalize. Hence, always call flush or finalize after you have finished writing to the stream.
Parameters:
OutputStream | outStream | Any java.io.OutputStream. | ||
Environ | env | The Netica environment the stream is created in |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); Streamer stream = new Streamer (baos, net.getEnviron()); net.write (stream); stream.flush(); // The byte array of baos now contains the net serialized in the standard .dne format.
Method Detail |
public Environ getEnviron() throws NeticaException
public java.lang.String getFileName() throws NeticaException
If this stream is not associated with a file, then null is returned.
Version:
Streamer(String, Environ) | Streamer constructor that sets filename. | |
Streamer(String) | Streamer constructor that sets filename. | |
Net(Streamer) | Initializes net's filename with the name of the file read, if the input stream was a file. | |
Net.getFileName | Similar, but for a Net. |
public void flush() throws NeticaException
Both the Streamer and the OutputStream remain open for potentially further flushes.
If called on any other kind of Streamer, does nothing.
Example:
See the example for Streamer(OutputStream).
public void finalize() throws NeticaException
If this Streamer was constructed with either Streamer(String, Environ) or Streamer(String) then the associated file will be closed first.
On the other hand, if either Streamer(OutputStream) or Streamer(InputStream) was used, then the associated OutputStream or InputStream will remain open (when a java.io.InputStream or java.io.OutputStream is closed, it cannot be re-opened).
If Streamer(OutputStream) was used to construct this Streamer, this method will flush the associated java.io.OutputStream.
If you override this method, be sure to call the base class method (super.finalize();).
Version:
Streamer | Creates a new Streamer |
finalize
in class java.lang.Object
public void close() throws NeticaException
finalize
instead.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |