NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

[Fwd: Re: Problems w NetcdfFile.openInMemory]

  • Subject: [Fwd: Re: Problems w NetcdfFile.openInMemory]
  • From: John Caron <caron@xxxxxxxxxxxxxxxx>
  • Date: Mon, 27 Jun 2005 18:14:45 -0600


-------- Original Message --------
Subject:        Re: Problems w NetcdfFile.openInMemory
Date:   Mon, 27 Jun 2005 18:02:34 -0600
From:   John Caron <caron@xxxxxxxxxxxxxxxx>
To:     Stuart Maclean <stuart@xxxxxxxxxxxxxxxxxx>
References:     <Pine.LNX.4.58.0506271544590.3313@xxxxxxxxxxxxxxxxxxxxxxxx>



Stuart Maclean wrote:

I'm trying to load netcdf data in an app with no local 'filesystem', such
as a jnlp (web start) environment.  Looks like the best bet, given the
Java Netcdf API, is to locate the data as as resource
(Class.getResourceAsStream). I can thus get the data into a byte[].

But passing that byte[] to NetcdfFile.openInMemory fails with a NPE.
Looking at the latest (2.2.09) sources, it seems that the
InMemoryRandomAccessFile is broken.  The 'buffer' attribute is attached to
the incoming data buf only after a call to 'init(1)' occurs.  The
superclass RandomAccessFile is thus is a bad state, causing an eventual
NPE.

Any help gratefully apprteciated,

Stuart
Ok, if you are compiling from source, just move the buffer assignment up:

 public InMemoryRandomAccessFile(String location, byte[] data)  {
   super(1);
   this.location = location;
   this.file = null;
       if (data == null)
           throw new IllegalArgumentException("data array is null");

   buffer = data;
   bufferStart = 0;
   dataSize = buffer.length;
   dataEnd = buffer.length;
   filePosition = 0;
   endOfFile = false;
 }

otherwise, i will have a new release (2.2.10) in an hour or so

thanks for finding that bug!




  • 2005 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: