NORSYS SOFTWARE © 2012 | NETICA API | JAVA VERSION 5.04 |
|
|||||||||
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.writeFindings | ||
Net.readFindings |
Constructor Summary | |
Streamer(java.io.InputStream inStream,
java.lang.String streamName,
Environ env)
Constructs a Norsys stream from a java.io.InputStream. |
|
Streamer(java.io.OutputStream outStream,
java.lang.String streamName,
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 resources (e.g., memory) used by this Streamer. |
void |
flush()
For a Streamer constructed from a java.io.OutputStream (see Streamer(OutputStream,String,Environ)), 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. |
void |
setPassword(java.lang.String password)
Sets the password that Netica will use for either encrypting an output stream, or for decrypting an input stream. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Streamer ( |
| ) throws NeticaException |
String | filename | Path to the file to attach to this stream. |
Streamer(String,Environ) | Same, but for any environment | |
finalize | Delete it when done |
// // 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");;
public Streamer ( |
| ) 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 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.writeFindings | ||
Net.readFindings | ||
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", env); Streamer file = new Streamer ("/local/project1/configure.bn.txt", env); Streamer file = new Streamer ("../nets/Umbrella.dne", env); // // Examples for MS Windows // Streamer file = new Streamer ("temp3", env); Streamer file = new Streamer ("C:local\\project1\\configur.txt", env); Streamer file = new Streamer ("..\\nets\\Umbrella.dne", env); // // Examples for MacOS // Streamer file = new Streamer ("temp3", env); Streamer file = new Streamer ("local:project1:configure.bn.txt", env); Streamer file = new Streamer ("::nets:Umbrella.dne", env);
public Streamer ( |
| ) throws NeticaException |
streamName is a name that will be assigned the stream internally by Netica. Should there be any problem with the stream, any exceptions thrown will use this name for describing the problem. Also, the name is the basis for making any formatting decisions, in interpreting the stream contents. For instance, if the stream will be given to a Net constructor, then if streamName ends with ".neta", the stream will be assumed to contain a net in the binary .neta file format.
If inStream is a java.io.FileInputStream then be aware that streamName is entirely independent from the file's name. Hence, to avoid confusion, it is recommended that you use the file's name for streamName. For convenience in such a case, rather than this method, you may prefer to use Streamer(String filename).
Parameters:
java.io.InputStream | inStream | Any java.io.InputStream. | ||
String | streamName | A symbolic name to be assigned the stream, for formatting and error logging purposes. | ||
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, "myStringBuf.dne", Environ.getDefaultEnviron()));
public Streamer ( |
| ) throws NeticaException |
streamName is a name that will be assigned the stream internally by Netica. Should there be any problem with the stream, any exceptions thrown will use this name for describing the problem. Also, the name is the basis for making any formatting decisions, in filling or emptying the stream. For instance, if the stream will be filled using Net.write
, then if streamName ends with ".neta", the stream will filled using the binary .neta file format for nets, otherwise the ".dnet" format will be used.
If outStream is a java.io.FileOutputStream then be aware that streamName is entirely independent from the file's name. Hence, to avoid confusion, it is recommended that you use the file's name for streamName. For convenience in such a case, rather than this method, you may prefer to use Streamer(String filename).
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:
java.io.OutputStream | outStream | Any java.io.OutputStream. | ||
String | streamName | A symbolic name to be assigned the stream, for formatting and error logging purposes. | ||
Environ | env | The Netica environment the stream is created in |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); Streamer stream = new Streamer (baos, "myByteArray.dne", net.getEnviron()); net.write (stream); stream.flush(); // The byte array of baos now contains the net serialized in the standard .dne/.dnet format.
Method Detail |
public void finalize ( ) throws NeticaException |
If this Streamer was constructed with either Streamer(String, Environ) or Streamer(String) then that file will be closed, if necessary, but will not be deleted.
On the other hand, if either Streamer(OutputStream,String,Environ) or Streamer(InputStream,String,Environ) 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,String,Environ) 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 file Streamer | |
NewMemoryStreamer | Creates a new memory Streamer |
finalize
in class java.lang.Object
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:
public Environ getEnviron ( ) throws NeticaException |
public 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 setPassword ( |
| ) throws NeticaException |
Encryption/decryption is only possible for certain file formats (e.g., ".neta"). The file format is specified when the stream is created (see Streamer or NewMemoryStreamer). If strm is not for a format that allows encryption/decryption (such as .dne, .cas, .xml, or .txt), then an exception will be thrown.
If the password supplied for reading an encrypted source is not the same password that was used by Netica to encrypt that source, then an exception will be thrown when you attempt to read from that source.
Pass null for password to remove it, so that subsequent reading/writing from this stream will be without any encryption/decryption.
Parameters:
String | password | The text string to use for en/decryption |
Streamer | Create new file stream | |
NewMemoryStreamer | Create new memory stream | |
Streamer stream = new Streamer( "myNet.neta" ); stream.setPassword( "myPassword123" ); net.write( stream ); ... Streamer stream2 = new Streamer( "myNet.neta" ); stream2.setPassword( "myPassword123" ); Net net2 = new Net( stream2 ); // reads back in the encrypted file ... Streamer stream3 = new Streamer( "myNet.neta" ); stream3.setPassword( "wrongPassword456" ); Net net3 = new Net( stream3 ); // throws exception, since password is incorrect
public void close ( ) throws NeticaException |
finalize
instead.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |