Pointer implements Closeable { @Nonnull public static Pointer<CLong> nref(@Nonnull final CLong... val) { final int length = Objects.requireNonNull(val, "Argument val must not be null").length; if (length == 0) { throw new IllegalArgumentException("Cannot allocate zero length array."); } final Class<? extends CLong> componentType = val[0].getClass(); final Pointer<CLong> pointer = (Pointer<CLong>) createStack(componentType, Size.sizeof((CLong) null), length); for (int i = 0; i < length; i++) { pointer.set(i, val[i]); } return pointer; } Pointer(@Nonnull final Type type,
            final long address,
            final boolean autoFree,
            final int typeSize); @Nonnull static Pointer<Void> wrap(@Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      @Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<Void> wrap(final long address); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      final long address); static Pointer<Void> realloc(@Nonnull Pointer<?> pointer,
                                        @Nonnegative final int size); static Pointer<U> realloc(@Nonnull Pointer<?> pointer,
                                         @Nonnegative final int size,
                                         @Nonnull final Class<U> type); @Nonnull static Pointer<Void> malloc(@Nonnegative final int size); @Nonnull static Pointer<U> malloc(@Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<Void> calloc(@Nonnegative final int nmemb,
                                       @Nonnegative final int size); @Nonnull static Pointer<U> calloc(@Nonnegative final int nmemb,
                                        @Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<CLong> nref(@Nonnull final CLong... val); static Pointer<Object> from(@Nonnull final Object val); @Nonnull static Pointer<U> ref(@Nonnull final U val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @Nonnull static Pointer<Byte> nref(@Nonnull final byte... val); @Nonnull static Pointer<Short> nref(@Nonnull final short... val); @Nonnull static Pointer<Integer> nref(@Nonnull final int... val); @Nonnull static Pointer<Float> nref(@Nonnull final float... val); @Nonnull static Pointer<Long> nref(@Nonnull final long... val); @Nonnull static Pointer<Double> nref(@Nonnull final double... val); @Nonnull static Pointer<String> nref(@Nonnull final String val); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); void close(); @Nonnull abstract T get(); @Nonnull abstract T get(@Nonnegative final int index); @Nonnull final Pointer<T> inc(); @Nonnull final Pointer<T> dec(); @Nonnull final Pointer<T> plus(final int value); @Nonnull final Pointer<T> minus(final int value); @Nonnull Pointer<U> castp(@Nonnull final Class<U> type); @Nonnull Pointer<Pointer<T>> castpp(); abstract void set(@Nonnull final T val); abstract void set(@Nonnegative final int index,
                             @Nonnull final T val); final long address; }
@Test public void testsetFloat() throws Exception { final float f0 = 0x45678901; final float f1 = 0x12345678; final Pointer<Float> floatPointer = Pointer.nref(f0, f1); assertThat(JNITestUtil.getFloat(floatPointer.address)).isEqualTo(f0); assertThat(JNITestUtil.getFloat(floatPointer.address + 4)).isEqualTo(f1); }
@Test public void testsetLong() throws Exception { final long l0 = 0x4567890123456789L; final long l1 = 0x1234567890123456L; final Pointer<Long> longPointer = Pointer.nref(l0, l1); assertThat(JNITestUtil.getByte(longPointer.address)).isEqualTo((byte) 0x89); assertThat(JNITestUtil.getByte(longPointer.address + 1)).isEqualTo((byte) 0x67); assertThat(JNITestUtil.getByte(longPointer.address + 2)).isEqualTo((byte) 0x45); assertThat(JNITestUtil.getByte(longPointer.address + 3)).isEqualTo((byte) 0x23); assertThat(JNITestUtil.getByte(longPointer.address + 4)).isEqualTo((byte) 0x01); assertThat(JNITestUtil.getByte(longPointer.address + 5)).isEqualTo((byte) 0x89); assertThat(JNITestUtil.getByte(longPointer.address + 6)).isEqualTo((byte) 0x67); assertThat(JNITestUtil.getByte(longPointer.address + 7)).isEqualTo((byte) 0x45); assertThat(JNITestUtil.getByte(longPointer.address + 8)).isEqualTo((byte) 0x56); assertThat(JNITestUtil.getByte(longPointer.address + 9)).isEqualTo((byte) 0x34); assertThat(JNITestUtil.getByte(longPointer.address + 10)).isEqualTo((byte) 0x12); assertThat(JNITestUtil.getByte(longPointer.address + 11)).isEqualTo((byte) 0x90); assertThat(JNITestUtil.getByte(longPointer.address + 12)).isEqualTo((byte) 0x78); assertThat(JNITestUtil.getByte(longPointer.address + 13)).isEqualTo((byte) 0x56); assertThat(JNITestUtil.getByte(longPointer.address + 14)).isEqualTo((byte) 0x34); assertThat(JNITestUtil.getByte(longPointer.address + 15)).isEqualTo((byte) 0x12); }
@Test public void testsetDouble() throws Exception { final double d0 = 0x4567_8901_2345_6789L; final double d1 = 0x1234_5678_9012_3456L; final Pointer<Double> doublePointer = Pointer.nref(d0, d1); assertThat((float) JNITestUtil.getDouble(doublePointer.address)).isEqualTo((float) d0); assertThat((float) JNITestUtil.getDouble(doublePointer.address + 8)).isEqualTo((float) d1); }
@Test public void testsetCLong() throws Exception { final CLong cl0 = new CLong(0x45678901); final CLong cl1 = new CLong(0x12345678); final Pointer<CLong> cLongPointer = Pointer.nref(cl0, cl1); assertThat(JNITestUtil.getCLong(cLongPointer.address)).isEqualTo(cl0.longValue()); assertThat(JNITestUtil.getCLong(cLongPointer.address + sizeof((CLong) null))).isEqualTo(cl1.longValue()); }
@Test public void testsetByte() throws Exception { final byte b0 = 0x45; final byte b1 = 0x67; final byte b2 = 0x76; final Pointer<Byte> bytePointer = Pointer.nref(b0, b1, b2); assertThat(JNITestUtil.getByte(bytePointer.address)).isEqualTo(b0); assertThat(JNITestUtil.getByte(bytePointer.address + 1)).isEqualTo(b1); assertThat(JNITestUtil.getByte(bytePointer.address + 2)).isEqualTo(b2); }
@Test public void testsetShort() throws Exception { final short s0 = 0x4567; final short s1 = (short) 0x8901; final Pointer<Short> shortPointer = Pointer.nref(s0, s1); assertThat(JNITestUtil.getByte(shortPointer.address)).isEqualTo((byte) 0x67); assertThat(JNITestUtil.getByte(shortPointer.address + 1)).isEqualTo((byte) 0x45); assertThat(JNITestUtil.getByte(shortPointer.address + 2)).isEqualTo((byte) 0x01); assertThat(JNITestUtil.getByte(shortPointer.address + 3)).isEqualTo((byte) 0x89); }
@Test public void testWriteInt() throws Exception { final int i0 = 0x45678901; final int i1 = 0x12345678; final Pointer<Integer> integerPointer = Pointer.nref(i0, i1); assertThat(JNITestUtil.getByte(integerPointer.address)).isEqualTo((byte) 0x01); assertThat(JNITestUtil.getByte(integerPointer.address + 1)).isEqualTo((byte) 0x89); assertThat(JNITestUtil.getByte(integerPointer.address + 2)).isEqualTo((byte) 0x67); assertThat(JNITestUtil.getByte(integerPointer.address + 3)).isEqualTo((byte) 0x45); assertThat(JNITestUtil.getByte(integerPointer.address + 4)).isEqualTo((byte) 0x78); assertThat(JNITestUtil.getByte(integerPointer.address + 5)).isEqualTo((byte) 0x56); assertThat(JNITestUtil.getByte(integerPointer.address + 6)).isEqualTo((byte) 0x34); assertThat(JNITestUtil.getByte(integerPointer.address + 7)).isEqualTo((byte) 0x12); }