I have a netcdf file which I am opening in memory and trying to get a binary representation of that file. Unfortunately, there does not seem to be a method that allows this.
I've tried using an ObjectOutputStream and a DataOutputStream but none seem to work:
// Nothing gets writen into baos
NetcdfFile file = NetcdfFile.openInMemory("C:\\testVIL.nc");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
N3outputStreamWriter w = new N3outputStreamWriter(file);
w.writeDataAll(out);
out.close();
byte[] byteArray = baos.toByteArray();
for ( byte b : byteArray ) {
System.out.print( (char) b );
}
// netcdfFile is not seralizable
NetcdfFile file = NetcdfFile.openInMemory("C:\\testVIL.nc");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( file );
byte[] byteArray = baos.toByteArray();
for ( byte b : byteArray ) {
System.out.print( (char) b );
}
Can anyone suggest a way for me to get a binary representation for the netcdf file, I'm stumped!