MCPcopy Index your code
hub / github.com/java-native-access/jna / readArray

Method readArray

src/com/sun/jna/Pointer.java:458–533  ·  view source on GitHub ↗

Read memory starting at offset into the array with element type cls.

(long offset, Object o, Class<?> cls)

Source from the content-addressed store, hash-verified

456
457 /** Read memory starting at offset into the array with element type cls. */
458 private void readArray(long offset, Object o, Class<?> cls) {
459 int length = 0;
460 length = Array.getLength(o);
461 Object result = o;
462
463 if (cls == byte.class) {
464 read(offset, (byte[])result, 0, length);
465 }
466 else if (cls == short.class) {
467 read(offset, (short[])result, 0, length);
468 }
469 else if (cls == char.class) {
470 read(offset, (char[])result, 0, length);
471 }
472 else if (cls == int.class) {
473 read(offset, (int[])result, 0, length);
474 }
475 else if (cls == long.class) {
476 read(offset, (long[])result, 0, length);
477 }
478 else if (cls == float.class) {
479 read(offset, (float[])result, 0, length);
480 }
481 else if (cls == double.class) {
482 read(offset, (double[])result, 0, length);
483 }
484 else if (Pointer.class.isAssignableFrom(cls)) {
485 read(offset, (Pointer[])result, 0, length);
486 }
487 else if (Structure.class.isAssignableFrom(cls)) {
488 Structure[] sarray = (Structure[])result;
489 if (Structure.ByReference.class.isAssignableFrom(cls)) {
490 Pointer[] parray = getPointerArray(offset, sarray.length);
491 for (int i=0;i < sarray.length;i++) {
492 sarray[i] = Structure.updateStructureByReference((Class<Structure>) cls, sarray[i], parray[i]);
493 }
494 }
495 else {
496 Structure first = sarray[0];
497 if (first == null) {
498 first = Structure.newInstance((Class<Structure>) cls, share(offset));
499 first.conditionalAutoRead();
500 sarray[0] = first;
501 }
502 else {
503 first.useMemory(this, (int)offset, true);
504 first.read();
505 }
506 Structure[] tmp = first.toArray(sarray.length);
507 for (int i=1;i < sarray.length;i++) {
508 if (sarray[i] == null) {
509 // Structure.toArray() takes care of read
510 sarray[i] = tmp[i];
511 }
512 else {
513 sarray[i].useMemory(this, (int)(offset + i * sarray[i].size()), true);
514 sarray[i].read();
515 }

Callers 1

getValueMethod · 0.95

Calls 15

readMethod · 0.95
getPointerArrayMethod · 0.95
newInstanceMethod · 0.95
shareMethod · 0.95
conditionalAutoReadMethod · 0.95
useMemoryMethod · 0.95
readMethod · 0.95
toArrayMethod · 0.95
getInstanceMethod · 0.95
getNativeSizeMethod · 0.95
getValueMethod · 0.95

Tested by

no test coverage detected