16 package org.nexusformat;
18 import java.util.Hashtable;
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);
108 protected native
void close(
int handle);
109 protected native
int nxflush(
int handle);
131 checkForNull(filename);
133 handle =
init(filename,access);
143 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
175 protected native
void nxmakegroup(
int handle, String name, String nxclass);
176 protected native
void nxopengroup(
int handle, String name, String nxclass);
177 protected native
void nxopenpath(
int handle, String path);
180 protected native String
nxgetpath(
int handle);
183 checkForNull(name, nxclass);
184 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
189 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
190 checkForNull(name, nxclass);
195 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
201 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
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[]);
222 protected native
void nxopendata(
int handle, String name);
224 protected native
void nxcompress(
int handle,
int compression_type);
228 if (handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
230 checkForNull(name, rank, iChunk);
231 checkForNegInArray(
true, dim, iChunk);
232 switch(compression_type) {
240 nxmakecompdata(handle, name, type, rank, dim, compression_type, iChunk);
245 if (handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
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
262 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
264 checkForNull(name, dim);
265 checkForNegInArray(
true, dim);
269 public void makedata(String name,
int type,
int rank,
long dim[])
throws
271 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
273 checkForNull(name, dim);
274 checkForNegInArray(
true, dim);
279 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
285 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
290 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
291 switch(compression_type) {
306 protected native
void nxgetdata(
int handle, byte bdata[]);
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[]);
313 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
327 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
328 checkForNull(start, size, array);
329 checkForNegInArray(
false, start, size);
342 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
343 checkForNull(start, size, array);
344 checkForNegInArray(
false, start, size);
357 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
359 checkForNull(name, array);
372 protected native
void nxputdata(
int handle, byte 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);
380 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
397 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
398 checkForNull(array, start, size);
399 checkForNegInArray(
false, start, size);
414 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
415 checkForNull(array, start, size);
416 checkForNegInArray(
false, start, size);
431 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
433 checkForNull(name, array);
447 protected native
void nxgetinfo(
int handle,
int iDim[],
int args[]);
448 protected native
void nxgetinfo64(
int handle,
long iDim[],
int args[]);
451 protected native
int nextentry(
int handle, String names[]);
452 protected native
int nextattr(
int handle, String names[],
int args[]);
457 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
459 checkForNull(format);
464 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
469 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
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");
493 while(
nextattr(handle,names,args) != -1)
512 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
519 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
526 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
527 checkForNull(target);
532 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
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) {
559 if (value == this.NX_UNLIMITED && allowUnlimited) {
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) {
574 if (value == this.NX_UNLIMITED && allowUnlimited) {
577 throw new IllegalArgumentException(
"negative dimension received");
587 private void checkType(
int type)
throws NexusException {
602 throw new NexusException(
"Illegal number type requested");
608 protected native
void nxinquirefile(
int handle, String names[]);
609 protected native
void nxlinkexternal(
int handle, String name, String nxclass, String nxurl);
611 protected native
int nxisexternalgroup(
int handle, String name, String nxclass, String nxurl[]);
615 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
616 String names[] =
new String[1];
622 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
623 checkForNull(name, nxclass, nxurl);
628 if(handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
629 checkForNull(name, nxurl);
634 if (handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
635 checkForNull(name, nxclass);
636 String nxurl[] =
new String[1];
647 if (handle < 0)
throw new NexusException(
"NAPI-ERROR: File not open");
649 String nxurl[] =
new String[1];
int length
length is the length of the attribute.
Object arrayify(byte[] bytes)
Given a one-dimensional array of numbers, convert it to a java array of the shape and size passed to ...
byte[] byteify()
Given a Java array of numbers, convert it to a one-dimensional array of bytes in correct native order...
byte[] emptyBytes()
allocate a one-dimensional array of bytes sufficient to store the array.
This is a class for handling multidimensional arrays for HDF.