norsys.netica
Class Streamer

java.lang.Object
  |
  +--norsys.netica.Streamer

public class Streamer
extends java.lang.Object

An I/O handle to a file (for reading, writing, etc).

Since:
2.08

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)
          Returns a Norsys stream for the file with name filename, for the current default Environ (see getDefaultEnviron).
Streamer(java.lang.String fileName, Environ env)
          Returns a Norsys stream for the file with name filename.
 
Method Summary
 void close()
          Releases the memory used by the this Streamer.
 void finalize()
          See close.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Streamer

public Streamer(java.lang.String fileName)
         throws NeticaException
Returns a Norsys stream for the file with name filename, for the current default Environ (see getDefaultEnviron). A convenience method, otherwise identical to Streamer(String, Environ). See that method for further documentation.

Parameters:
filename - Path to the file to attach to this stream.

Streamer

public Streamer(java.lang.String fileName,
                Environ env)
         throws NeticaException
Returns a Norsys stream for the file with name filename.

This stream can then be passed as an argument to functions 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 close.

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.

Version:

In the C Version of the API, this function is called NewStreamFile_ns.
See Also:
close  Delete it when done
write  Saves a net to a file with name specified by the passed stream
Net(Streamer)  Reads a net from the file identified by the passed stream

Example:

 //
 // Examples for UNIX / Linux
 //
 Streamer file = new Streamer ("temp3");
 Streamer file = new Streamer ("/local/project1/configure.bn.txt");
 Streamer file = new Streamer ("../nets/Umbrella.dnet");
 //
 // Examples for MS Windows
 //
 Streamer file = new Streamer ("temp3");
 Streamer file = new Streamer ("C:local\\project1\\configur.txt");
 Streamer file = new Streamer ("..\\nets\\Umbrella.dnt");
 //
 // Examples for MacOS
 //
 Streamer file = new Streamer ("temp3");
 Streamer file = new Streamer ("local:project1:configure.bn.txt");
 Streamer file = new Streamer ("::nets:Umbrella.dnet");
Parameters:
filename - Path to the file to attach to this stream.
env -  

Streamer

public Streamer(java.io.InputStream inStream,
                Environ env)
         throws NeticaException
Constructs a Norsys stream from a java.io.InputStream. If inStream is a java.io.FileInputStream and you want Netica to know the name of the file, then use Streamer(String filename) instead.

Parameters:
inStream - Any java.io.InputStream.

Streamer

public Streamer(java.io.OutputStream outStream,
                Environ env)
         throws NeticaException
Constructs a Norsys stream from a java.io.OutputStream. If outStream is a java.io.FileOutputStream and you want Netica to know the name of the file, then use Streamer(String filename) instead.

Note: The outStream is only guaranteed to be filled after calling flush or close. Hence, always call flush or close after you have finished writing to the stream.

Example:

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 Streamer stream = new Streamer( baos, net.getEnviron() );
 net.write( stream );
 stream.flush();
Parameters:
outStream - Any java.io.OutputStream.
Method Detail

flush

public void flush()
           throws NeticaException
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.

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

finalize

public void finalize()
              throws NeticaException
See close.

If you override this method, be sure to call the base class method (super.finalize();).

Overrides:
finalize in class java.lang.Object

close

public void close()
           throws NeticaException
Releases the memory used by the this Streamer. Does not delete the actual file.

If this Streamer was constructed with either Streamer(String, Environ) or Streamer(String) then the associated file will be closed before deleting.

On the other hand, if either Streamer(OutputStream) or Streamer(InputStream) was used, then the associated OutputStream or InputStream is in no way affected by the closing of this stream.

Version:

Versions 2.09 and later have this function.
In the C Version of the API, this function is called DeleteStream_ns.
See Also:
Streamer  Creates a new Streamer