I'm using the Netica Java library in my code to read in a bayes net, enter findings, and save the updated bayes net in a byte array. The byte array saves perfectly fine (as far as I can tell) but I can't seem to load it back in using the ByteArrayInputStream.
My code is:
Environ env = new EnvironI( null );
ByteArrayInputStream bais = new ByteArrayInputStream( myBinaryData );
bais.close();
Net model = new Net( new Streamer( bais, "templateFile.neta", env );
It fails on the last line with the following error:
stderr: norsys.netica.NeticaException:
************** E R R O R ***************
** ErrorNumber = 2734
** ErrorSeverity = ERROR_ERR
** ErrorCategory =
** ErrorMessage = In function Net(Streamer inStream) constructor: buffer to decompress gzip 'internal' is too small (is 3082 but -981804177 needed)
Note that there are specific applications of the Netica library here. I should also note that this works fine on my OSX machine but seems to break on a Linux box.
Any ideas?
I have determined the issue.
I mentioned that I read in a bayes net prior and that code looks like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Streamer stream = new Streamer( baos, "myNetaFile.neta", env );
net.write( stream );
byte[] bytesToEncode = baos.toByteArray();
stream.flush();
String encoded = Base64.encodeBase64String( bytesToEncode );
The above code is actually correct. The binary was getting corrupted somehow when I was reading it back in. My issue was I had the .toByteArray() and .flush() lines swapped.
If anybody else runs into this issue using Netica, keep in mind correct order of operations!