16 package org.nexusformat;
18 import java.util.Hashtable;
20 import ncsa.hdf.hdflib.HDFArray;
21 import ncsa.hdf.hdflib.HDFException;
22 import ncsa.hdf.hdflib.HDFConstants;
83 String filename = null;
84 filename = System.getProperty(
"org.nexusformat.JNEXUSLIB",null);
85 if ((filename != null) && (filename.length() > 0))
87 File hdfdll =
new File(filename);
88 if (hdfdll.exists() && hdfdll.canRead() && hdfdll.isFile())
90 System.load(filename);
92 throw (
new UnsatisfiedLinkError(
"Invalid JNEXUS library"));
96 System.loadLibrary(
"jnexus");
107 protected native
int init(String filename,
int access);
131 checkForNull(filename);
143 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
183 checkForNull(name, nxclass);
190 checkForNull(name, nxclass);
207 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
212 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
218 protected native
void nxmakedata(
int handle, String name,
int type,
int rank,
int dim[]);
219 protected native
void nxmakedata64(
int handle, String name,
int type,
int rank,
long dim[]);
220 protected native
void nxmakecompdata(
int handle, String name,
int type,
int rank,
int dim[],
int iCompress,
int iChunk[]);
221 protected native
void nxmakecompdata64(
int handle, String name,
int type,
int rank,
long dim[],
int iCompress,
long iChunk[]);
230 checkForNull(name, rank, iChunk);
231 checkForNegInArray(
true, dim, iChunk);
232 switch(compression_type) {
247 checkForNull(name, rank, iChunk);
248 checkForNegInArray(
true, dim, iChunk);
249 switch(compression_type) {
260 public void makedata(String name,
int type,
int rank,
int dim[])
throws
264 checkForNull(name, dim);
265 checkForNegInArray(
true, dim);
269 public void makedata(String name,
int type,
int rank,
long dim[])
throws
273 checkForNull(name, dim);
274 checkForNegInArray(
true, dim);
285 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
291 switch(compression_type) {
307 protected native
void nxgetslab(
int handle,
int Start[],
int size[], byte bdata[]);
308 protected native
void nxgetslab64(
int handle,
long Start[],
long size[], byte bdata[]);
309 protected native
void nxgetattr(
int handle, String name, byte bdata[],
int args[]);
328 checkForNull(start, size, array);
329 checkForNegInArray(
false, start, size);
343 checkForNull(start, size, array);
344 checkForNegInArray(
false, start, size);
359 checkForNull(name, array);
373 protected native
void nxputslab(
int handle, byte array[],
int start[],
int size[]);
374 protected native
void nxputslab64(
int handle, byte array[],
long start[],
long size[]);
375 protected native
void nxputattr(
int handle, String name, byte array[],
int type);
398 checkForNull(array, start, size);
399 checkForNegInArray(
false, start, size);
415 checkForNull(array, start, size);
416 checkForNegInArray(
false, start, size);
433 checkForNull(name, array);
452 protected native
int nextattr(
int handle, String names[],
int args[]);
459 checkForNull(format);
474 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
475 Hashtable h =
new Hashtable();
476 String names[] =
new String[2];
480 h.put(names[0],names[1]);
486 int args[] =
new int[2];
488 String names[] =
new String[1];
490 Hashtable h =
new Hashtable();
491 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
512 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
519 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
527 checkForNull(target);
533 checkForNull(name, target);
538 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
546 private void checkForNull(Object... args) {
547 for (Object o : args)
548 if (o==null)
throw new NullPointerException();
555 private void checkForNegInArray(
boolean allowUnlimited,
int[]... args) {
556 for (
int[] array : args)
557 for (
int value: array) {
562 throw new IllegalArgumentException(
"negative dimension received");
570 private void checkForNegInArray(
boolean allowUnlimited,
long[]... args) {
571 for (
long[] array : args)
572 for (
long value: array) {
577 throw new IllegalArgumentException(
"negative dimension received");
587 private void checkType(
int type)
throws NexusException {
602 throw new NexusException(
"Illegal number type requested");
615 if(
handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
616 String names[] =
new String[1];
623 checkForNull(name, nxclass, nxurl);
629 checkForNull(name, nxurl);
635 checkForNull(name, nxclass);
636 String nxurl[] =
new String[1];
649 String nxurl[] =
new String[1];