Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

Since:
  2.08
Version:
  2.20 - May 7, 2002

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 `finalize` instead.
`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

### Streamer

    public Streamer(java.lang.String fileName)
             throws NeticaException

  Constructs a Norsys stream for the file with name filename, in the current default Environ (see getDefaultEnviron). A convenience method, otherwise identical to Streamer(String, Environ). See that method for further documentation.
  Parameters:

  String |  | filename |  | Path to the file to attach to this stream.

### Streamer

    public Streamer(java.lang.String fileName,
                    Environ env)
             throws NeticaException

  Constructs a Norsys stream for the file with name filename.

  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

  Version:
  In the C Version of the API, this function is called NewStreamFile_ns.
  See Also:

  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

  Example #1:

         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");

### 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:

  InputStream |  | inStream |  | Any java.io.InputStream.
  Environ |  | env |  | The Netica environment the stream is created in

  Example:

         // 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()));

### 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 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

  Example:

         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

### getEnviron

    public Environ getEnviron()
                       throws NeticaException

  Returns this Streamer's environment.
  Version:
  Versions 2.20 and later have this method.

### getFileName

    public java.lang.String getFileName()
                                 throws NeticaException

  Returns the name of the file (including full path) that this stream was last written to or read from, if any.

  If this stream is not associated with a file, then null is returned.
  Version:

  Versions 2.20 and later have this method.
  See Also:

  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.

### 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

  Releases the memory used by 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 first.

  On the other hand, if either Streamer(OutputStream) or Streamer(InputStream) was used, then the associated OutputStream or InputStream will remain open.

  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:

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

  Streamer |  | Creates a new Streamer

  Overrides:
    `finalize` in class `java.lang.Object`

### close

    public void close()
               throws NeticaException

  Deprecated. Use `finalize` instead.

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD