1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* For details of the HDF libraries, see the HDF Documentation at:
* http://hdfgroup.org/HDF5/doc/
*
*/
/*
* This module contains the implementation of all the native methods
* used for number conversion. This is represented by the Java
* class HDFNativeData.
*
* These routines convert one dimensional arrays of bytes into
* one-D arrays of other types (int, float, etc) and vice versa.
*
* These routines are called from the Java parts of the Java-C
* interface.
*
* ***Important notes:
*
* 1. These routines are designed to be portable--they use the
* C compiler to do the required native data manipulation.
* 2. These routines copy the data at least once -- a serious
* but unavoidable performance hit.
*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <jni.h>
#include "hdf5.h"
#include "h5jni.h"
#include "nativeData.h"
/* returns int [] */
JNIEXPORT jintArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToInt___3B(JNIEnv *env, jclass clss, jbyteArray bdata)
{
jintArray rarray = NULL;
jboolean bb;
jbyte *barr = NULL;
jint *iarray = NULL;
jint *iap = NULL;
char *bp = NULL;
int blen;
int ii;
int len;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToInt: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToInt: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToInt: bdata length < 0");
}
len = blen / (int)sizeof(jint);
if (NULL == (rarray = ENVPTR->NewIntArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_INT_ARRAY(ENVONLY, rarray, iarray, &bb, "byteToInt: int array not pinned");
bp = (char *)barr;
iap = iarray;
for (ii = 0; ii < len; ii++) {
*iap = *(jint *)bp;
iap++;
bp += sizeof(jint);
} /* end for */
done:
if (iarray)
UNPIN_INT_ARRAY(ENVONLY, rarray, iarray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToInt___3B */
/* returns float [] */
JNIEXPORT jfloatArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToFloat___3B(JNIEnv *env, jclass clss,
jbyteArray bdata) /* IN: array of bytes */
{
jfloatArray rarray = NULL;
jboolean bb;
jfloat *farray = NULL;
jfloat *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
int len;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToFloat: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToFloat: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToFloat: bdata length < 0");
}
len = blen / (int)sizeof(jfloat);
if (NULL == (rarray = ENVPTR->NewFloatArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_FLOAT_ARRAY(ENVONLY, rarray, farray, &bb, "byteToFloat: float array not pinned");
bp = (char *)barr;
iap = farray;
for (ii = 0; ii < len; ii++) {
*iap = *(jfloat *)bp;
iap++;
bp += sizeof(jfloat);
} /* end for */
done:
if (farray)
UNPIN_FLOAT_ARRAY(ENVONLY, rarray, farray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToFloat___3B */
/* returns short [] */
JNIEXPORT jshortArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToShort___3B(JNIEnv *env, jclass clss,
jbyteArray bdata) /* IN: array of bytes */
{
jshortArray rarray = NULL;
jboolean bb;
jshort *sarray = NULL;
jshort *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
int len;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToShort: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToShort: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToShort: bdata length < 0");
}
len = blen / (int)sizeof(jshort);
if (NULL == (rarray = ENVPTR->NewShortArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_SHORT_ARRAY(ENVONLY, rarray, sarray, &bb, "byteToShort: short array not pinned");
bp = (char *)barr;
iap = sarray;
for (ii = 0; ii < len; ii++) {
*iap = *(jshort *)bp;
iap++;
bp += sizeof(jshort);
} /* end for */
done:
if (sarray)
UNPIN_SHORT_ARRAY(ENVONLY, rarray, sarray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToShort___3B */
/* returns long [] */
JNIEXPORT jlongArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToLong___3B(JNIEnv *env, jclass clss,
jbyteArray bdata) /* IN: array of bytes */
{
jlongArray rarray = NULL;
jboolean bb;
jlong *larray = NULL;
jlong *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
int len;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToLong: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToLong: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToLong: bdata length < 0");
}
len = blen / (int)sizeof(jlong);
if (NULL == (rarray = ENVPTR->NewLongArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_LONG_ARRAY(ENVONLY, rarray, larray, &bb, "byteToLong: long array not pinned");
bp = (char *)barr;
iap = larray;
for (ii = 0; ii < len; ii++) {
*iap = *(jlong *)bp;
iap++;
bp += sizeof(jlong);
} /* end for */
done:
if (larray)
UNPIN_LONG_ARRAY(ENVONLY, rarray, larray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToLong___3B */
/* returns double [] */
JNIEXPORT jdoubleArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToDouble___3B(JNIEnv *env, jclass clss,
jbyteArray bdata) /* IN: array of bytes */
{
jdoubleArray rarray = NULL;
jboolean bb;
jdouble *darray = NULL;
jdouble *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
int len;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToDouble: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToDouble: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToDouble: bdata length < 0");
}
len = blen / (int)sizeof(jdouble);
if (NULL == (rarray = ENVPTR->NewDoubleArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, &bb, "byteToDouble: double array not pinned");
bp = (char *)barr;
iap = darray;
for (ii = 0; ii < len; ii++) {
*iap = *(jdouble *)bp;
iap++;
bp += sizeof(jdouble);
} /* end for */
done:
if (darray)
UNPIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToDouble___3B */
/* returns int [] */
JNIEXPORT jintArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToInt__II_3B(JNIEnv *env, jclass clss, jint start, jint len,
jbyteArray bdata) /* IN: array of bytes */
{
jintArray rarray = NULL;
jboolean bb;
jint *iarray = NULL;
jint *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToInt: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToInt: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToInt: bdata length < 0");
}
if ((start < 0) || ((int)(start + (len * (int)sizeof(jint))) > blen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToInt: start < 0 or len exceeded buffer length");
bp = (char *)barr + start;
if (NULL == (rarray = ENVPTR->NewIntArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_INT_ARRAY(ENVONLY, rarray, iarray, &bb, "byteToInt: int array not pinned");
iap = iarray;
for (ii = 0; ii < len; ii++) {
*iap = *(jint *)bp;
iap++;
bp += sizeof(jint);
} /* end for */
done:
if (iarray)
UNPIN_INT_ARRAY(ENVONLY, rarray, iarray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToInt__II_3B */
/* returns short [] */
JNIEXPORT jshortArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToShort__II_3B(JNIEnv *env, jclass clss, jint start, jint len,
jbyteArray bdata) /* IN: array of bytes */
{
jshortArray rarray = NULL;
jboolean bb;
jshort *sarray = NULL;
jshort *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToShort: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToShort: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToShort: bdata length < 0");
}
if ((start < 0) || ((int)(start + (len * (int)sizeof(jshort))) > blen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToShort: start < 0 or len exceeded buffer length");
bp = (char *)barr + start;
if (NULL == (rarray = ENVPTR->NewShortArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_SHORT_ARRAY(ENVONLY, rarray, sarray, &bb, "byteToShort: short array not pinned");
iap = sarray;
for (ii = 0; ii < len; ii++) {
*iap = *(jshort *)bp;
iap++;
bp += sizeof(jshort);
} /* end for */
done:
if (sarray)
UNPIN_SHORT_ARRAY(ENVONLY, rarray, sarray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToShort__II_3B */
/* returns float [] */
JNIEXPORT jfloatArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToFloat__II_3B(JNIEnv *env, jclass clss, jint start, jint len,
jbyteArray bdata) /* IN: array of bytes */
{
jfloatArray rarray = NULL;
jboolean bb;
jfloat *farray = NULL;
jfloat *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToFloat: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToFloat: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToFloat: bdata length < 0");
}
if ((start < 0) || ((int)(start + (len * (int)sizeof(jfloat))) > blen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToFloat: start < 0 or len exceeded buffer length");
bp = (char *)barr + start;
if (NULL == (rarray = ENVPTR->NewFloatArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_FLOAT_ARRAY(ENVONLY, rarray, farray, &bb, "byteToFloat: float array not pinned");
iap = farray;
for (ii = 0; ii < len; ii++) {
*iap = *(jfloat *)bp;
iap++;
bp += sizeof(jfloat);
} /* end for */
done:
if (farray)
UNPIN_FLOAT_ARRAY(ENVONLY, rarray, farray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToFloat__II_3B */
/* returns long [] */
JNIEXPORT jlongArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToLong__II_3B(JNIEnv *env, jclass clss, jint start, jint len,
jbyteArray bdata) /* IN: array of bytes */
{
jlongArray rarray = NULL;
jboolean bb;
jlong *larray = NULL;
jlong *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToLong: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToLong: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToLong: bdata length < 0");
}
if ((start < 0) || ((int)(start + (len * (int)sizeof(jlong))) > blen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToLong: start < 0 or len exceeded buffer length");
bp = (char *)barr + start;
if (NULL == (rarray = ENVPTR->NewLongArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_LONG_ARRAY(ENVONLY, rarray, larray, &bb, "byteToLong: long array not pinned");
iap = larray;
for (ii = 0; ii < len; ii++) {
*iap = *(jlong *)bp;
iap++;
bp += sizeof(jlong);
} /* end for */
done:
if (larray)
UNPIN_LONG_ARRAY(ENVONLY, rarray, larray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToLong__II_3B */
/* returns double [] */
JNIEXPORT jdoubleArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToDouble__II_3B(JNIEnv *env, jclass clss, jint start, jint len,
jbyteArray bdata) /* IN: array of bytes */
{
jdoubleArray rarray = NULL;
jboolean bb;
jdouble *darray = NULL;
jdouble *iap = NULL;
jbyte *barr = NULL;
char *bp = NULL;
int blen;
int ii;
UNUSED(clss);
if (NULL == bdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "byteToDouble: byte array is NULL");
PIN_BYTE_ARRAY(ENVONLY, bdata, barr, &bb, "byteToDouble: byte array not pinned");
if ((blen = ENVPTR->GetArrayLength(ENVONLY, bdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToDouble: bdata length < 0");
}
if ((start < 0) || ((int)(start + (len * (int)sizeof(jdouble))) > blen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "byteToDouble: start < 0 or len exceeded buffer length");
bp = (char *)barr + start;
if (NULL == (rarray = ENVPTR->NewDoubleArray(ENVONLY, len)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, &bb, "byteToDouble: double array not pinned");
iap = darray;
for (ii = 0; ii < len; ii++) {
*iap = *(jdouble *)bp;
iap++;
bp += sizeof(jdouble);
} /* end for */
done:
if (darray)
UNPIN_DOUBLE_ARRAY(ENVONLY, rarray, darray, rarray ? 0 : JNI_ABORT);
if (barr)
UNPIN_BYTE_ARRAY(ENVONLY, bdata, barr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToDouble__II_3B */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_intToByte__II_3I(JNIEnv *env, jclass clss, jint start, jint len,
jintArray idata) /* IN: array of int */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
jint *ip = NULL;
jint *iarr = NULL;
int ilen;
int blen;
int ii;
int ij;
union things {
int ival;
char bytes[4];
} u;
UNUSED(clss);
if (NULL == idata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "intToByte: int array is NULL");
PIN_INT_ARRAY(ENVONLY, idata, iarr, &bb, "intToByte: int array not pinned");
if ((ilen = ENVPTR->GetArrayLength(ENVONLY, idata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "intToByte: idata length < 0");
}
if ((start < 0) || (((start + len)) > ilen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "intToByte: start < 0 or len exceeded buffer length");
ip = iarr + start;
blen = ilen * (int)sizeof(jint);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "intToByte: byte array not pinned");
bap = barray;
for (ii = 0; ii < len; ii++) {
u.ival = *ip++;
for (ij = 0; (size_t)ij < sizeof(jint); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT);
if (iarr)
UNPIN_INT_ARRAY(ENVONLY, idata, iarr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_intToByte__II_3I */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_shortToByte__II_3S(JNIEnv *env, jclass clss, jint start, jint len,
jshortArray sdata) /* IN: array of short */
{
jbyteArray rarray = NULL;
jboolean bb;
jshort *ip = NULL;
jshort *sarr = NULL;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ilen;
int blen;
int ii;
int ij;
union things {
short ival;
char bytes[4];
} u;
UNUSED(clss);
if (NULL == sdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "shortToByte: short array is NULL");
PIN_SHORT_ARRAY(ENVONLY, sdata, sarr, &bb, "shortToByte: short array not pinned");
if ((ilen = ENVPTR->GetArrayLength(ENVONLY, sdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "shortToByte: sdata length < 0");
}
if ((start < 0) || (((start + len)) > ilen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "shortToByte: start < 0 or len exceeded buffer length");
ip = sarr + start;
blen = ilen * (int)sizeof(jshort);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "shortToByte: byte array not pinned");
bap = barray;
for (ii = 0; ii < len; ii++) {
u.ival = *ip++;
for (ij = 0; (size_t)ij < sizeof(jshort); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT);
if (sarr)
UNPIN_SHORT_ARRAY(ENVONLY, sdata, sarr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_shortToByte__II_3S */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_floatToByte__II_3F(JNIEnv *env, jclass clss, jint start, jint len,
jfloatArray fdata) /* IN: array of float */
{
jbyteArray rarray = NULL;
jboolean bb;
jfloat *ip = NULL;
jfloat *farr = NULL;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ilen;
int blen;
int ii;
int ij;
union things {
float ival;
char bytes[4];
} u;
UNUSED(clss);
if (NULL == fdata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "floatToByte: float array is NULL");
PIN_FLOAT_ARRAY(ENVONLY, fdata, farr, &bb, "floatToByte: float array not pinned");
if ((ilen = ENVPTR->GetArrayLength(ENVONLY, fdata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "floatToByte: fdata length < 0");
}
if ((start < 0) || (((start + len)) > ilen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "floatToByte: start < 0 or len exceeded buffer length");
ip = farr + start;
blen = ilen * (int)sizeof(jfloat);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "floatToByte: byte array not pinned");
bap = barray;
for (ii = 0; ii < len; ii++) {
u.ival = *ip++;
for (ij = 0; (size_t)ij < sizeof(jfloat); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT);
if (farr)
UNPIN_FLOAT_ARRAY(ENVONLY, fdata, farr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_floatToByte__II_3F */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_doubleToByte__II_3D(JNIEnv *env, jclass clss, jint start, jint len,
jdoubleArray ddata) /* IN: array of double */
{
jbyteArray rarray = NULL;
jboolean bb;
jdouble *ip = NULL;
jdouble *darr = NULL;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ilen;
int blen;
int ii;
int ij;
union things {
double ival;
char bytes[8];
} u;
UNUSED(clss);
if (NULL == ddata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "doubleToByte: double array is NULL");
PIN_DOUBLE_ARRAY(ENVONLY, ddata, darr, &bb, "doubleToByte: double array not pinned");
if ((ilen = ENVPTR->GetArrayLength(ENVONLY, ddata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "doubleToByte: ddata length < 0");
}
if ((start < 0) || (((start + len)) > ilen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "doubleToByte: start < 0 or len exceeded buffer length");
ip = darr + start;
blen = ilen * (int)sizeof(jdouble);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "doubleToByte: byte array not pinned");
bap = barray;
for (ii = 0; ii < len; ii++) {
u.ival = *ip++;
for (ij = 0; (size_t)ij < sizeof(jdouble); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT);
if (darr)
UNPIN_DOUBLE_ARRAY(ENVONLY, ddata, darr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_doubleToByte__II_3D */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_longToByte__II_3J(JNIEnv *env, jclass clss, jint start, jint len,
jlongArray ldata) /* IN: array of long */
{
jbyteArray rarray = NULL;
jboolean bb;
jlong *ip = NULL;
jlong *larr = NULL;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ilen;
int blen;
int ii;
int ij;
union things {
jlong ival;
char bytes[8];
} u;
UNUSED(clss);
if (NULL == ldata)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "longToByte: long array is NULL");
PIN_LONG_ARRAY(ENVONLY, ldata, larr, &bb, "longToByte: long array not pinned");
if ((ilen = ENVPTR->GetArrayLength(ENVONLY, ldata)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "longToByte: ldata length < 0");
}
if ((start < 0) || (((start + len)) > ilen))
H5_BAD_ARGUMENT_ERROR(ENVONLY, "longToByte: start < 0 or len exceeded buffer length");
ip = larr + start;
blen = ilen * (int)sizeof(jlong);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, blen)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "longToByte: byte array not pinned");
bap = barray;
for (ii = 0; ii < len; ii++) {
u.ival = *ip++;
for (ij = 0; (size_t)ij < sizeof(jlong); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, rarray ? 0 : JNI_ABORT);
if (larr)
UNPIN_LONG_ARRAY(ENVONLY, ldata, larr, JNI_ABORT);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_longToByte__II_3J */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_intToByte__I(JNIEnv *env, jclass clss, jint idata) /* IN: int */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
int ival;
char bytes[sizeof(int)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jint))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "intToByte: byte array not pinned");
bap = barray;
u.ival = idata;
for (ij = 0; (size_t)ij < sizeof(jint); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_intToByte__I */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_floatToByte__F(JNIEnv *env, jclass clss, jfloat fdata) /* IN: float */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
float ival;
char bytes[sizeof(float)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jfloat))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "floatToByte: byte array not pinned");
bap = barray;
u.ival = fdata;
for (ij = 0; (size_t)ij < sizeof(jfloat); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_floatToByte__F */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_shortToByte__S(JNIEnv *env, jclass clss, jshort sdata) /* IN: short */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
short ival;
char bytes[sizeof(short)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jshort))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "shortToByte: byte array not pinned");
bap = barray;
u.ival = sdata;
for (ij = 0; (size_t)ij < sizeof(jshort); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_shortToByte__S */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_doubleToByte__D(JNIEnv *env, jclass clss, jdouble ddata) /* IN: double */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
double ival;
char bytes[sizeof(double)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jdouble))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "doubleToByte: byte array not pinned");
bap = barray;
u.ival = ddata;
for (ij = 0; (size_t)ij < sizeof(jdouble); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_doubleToByte__D */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_longToByte__J(JNIEnv *env, jclass clss, jlong ldata) /* IN: long */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
jlong ival;
char bytes[sizeof(jlong)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jlong))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "longToByte: byte array not pinned");
bap = barray;
u.ival = ldata;
for (ij = 0; (size_t)ij < sizeof(jlong); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_longToByte__J */
/* returns byte [] */
JNIEXPORT jbyteArray JNICALL
Java_hdf_hdf5lib_HDFNativeData_byteToByte__B(JNIEnv *env, jclass clss, jbyte bdata) /* IN: byte */
{
jbyteArray rarray = NULL;
jboolean bb;
jbyte *barray = NULL;
jbyte *bap = NULL;
int ij;
union things {
jbyte ival;
char bytes[sizeof(jbyte)];
} u;
UNUSED(clss);
if (NULL == (rarray = ENVPTR->NewByteArray(ENVONLY, sizeof(jbyte))))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
PIN_BYTE_ARRAY(ENVONLY, rarray, barray, &bb, "byteToByte: byte array not pinned");
bap = barray;
u.ival = bdata;
for (ij = 0; (size_t)ij < sizeof(jbyte); ij++) {
*bap = u.bytes[ij];
bap++;
} /* end for */
done:
if (barray)
UNPIN_BYTE_ARRAY(ENVONLY, rarray, barray, 0);
return rarray;
} /* end Java_hdf_hdf5lib_HDFNativeData_byteToByte__B */
#ifdef __cplusplus
} /* end extern "C" */
#endif /* __cplusplus */
|