/** * Indirect the native pointer to <code>malloc</code> space, a la * <code>Pointer.getByte</code>. But this method performs a bounds * checks to ensure that the indirection does not cause memory outside the * <code>malloc</code>ed space to be accessed. * * @see Pointer#getByte(long) */ @Override public byte getByte(long offset) { boundsCheck(offset, 1); return super.getByte(offset); }
public byte getValue() { return getPointer().getByte(0); }
/** Dump memory for debugging purposes. */ public String dump(long offset, int size) { final int BYTES_PER_ROW = 4; final String TITLE = "memory dump"; // estimate initial size assuming a 2 char line separator StringWriter sw = new StringWriter(TITLE.length() + 2 + size * 2 + (size / BYTES_PER_ROW * 4)); PrintWriter out = new PrintWriter(sw); out.println(TITLE); // byte[] buf = getByteArray(offset, size); for (int i=0;i < size;i++) { // byte b = buf[i]; byte b = getByte(offset + i); if ((i % BYTES_PER_ROW) == 0) out.print("["); if (b >=0 && b < 16) out.print("0"); out.print(Integer.toHexString(b & 0xFF)); if ((i % BYTES_PER_ROW) == BYTES_PER_ROW-1 && i < size-1) out.println("]"); } if (sw.getBuffer().charAt(sw.getBuffer().length() - 2) != ']') { out.println("]"); } return sw.toString(); }
result = Function.valueOf(getInt(offset) != 0); } else if (type == byte.class || type == Byte.class) { result = Byte.valueOf(getByte(offset)); } else if (type == short.class || type == Short.class) { result = Short.valueOf(getShort(offset));
public byte getByte(long offset) { return ptr.getByte(offset); }
/** * Given a pointer, reads an unsigned byte value. * * @param ptr Pointer. * * @param offset Byte offset from the pointer. * * @return Unsigned byte. */ public static int getUnsignedByte( Pointer ptr , long offset ) { return ptr.getByte( offset ) & 0x000000ff ; }
/** * @param lpszEnvironmentBlock The environment block as received from the * <A HREF="https://msdn.microsoft.com/en-us/library/windows/desktop/ms683187(v=vs.85).aspx">GetEnvironmentStrings</A> * function * @param offset Offset within the block to look for the entry * @param asWideChars If {@code true} then the block contains {@code wchar_t} * instead of "plain old" {@code char}s * @return The offset of the <U>first</U> {@code '\0'} in the data block * starting at the specified offset - can be the start offset itself if empty * string. * @see #isWideCharEnvironmentStringBlock */ public static long findEnvironmentStringBlockEntryEnd(Pointer lpszEnvironmentBlock, long offset, boolean asWideChars) { for (long curOffset=offset, stepSize=asWideChars ? 2L : 1L; ; curOffset += stepSize) { byte b=lpszEnvironmentBlock.getByte(curOffset); if (b == 0) { return curOffset; } } }
@Override public byte[] receive() { Pointer p = javaCanLibrary.receiveByteData(channelNumber, canId); if(p != null) { byte len = p.getByte(0); if(len <= 0) { System.out.println("It should not receive value less than 0 in normal can channel"); return null; } byte[] res = new byte[len]; for (int i = 0; i < len; i++) { res[i] = p.getByte(i + 1); } return res; } else return null; } }
/** * Indirect the native pointer to <code>malloc</code> space, a la * <code>Pointer.getByte</code>. But this method performs a bounds * checks to ensure that the indirection does not cause memory outside the * <code>malloc</code>ed space to be accessed. * * @see Pointer#getByte(long) */ public byte getByte(long offset) { boundsCheck(offset, 1); return super.getByte(offset); }
/** * Indirect the native pointer to <code>malloc</code> space, a la * <code>Pointer.getByte</code>. But this method performs a bounds * checks to ensure that the indirection does not cause memory outside the * <code>malloc</code>ed space to be accessed. * * @see Pointer#getByte(long) */ @Override public byte getByte(long offset) { boundsCheck(offset, 1); return super.getByte(offset); }
@Override public byte get() { return pointer.getByte(safeIncrementForGet()); }
@Override public byte get() { return pointer.getByte(safeIncrementForGet()); }
public byte getValue() { return getPointer().getByte(0); }
public byte getValue() { return getPointer().getByte(0); }
/** Dump memory for debugging purposes. */ public String dump(long offset, int size) { final int BYTES_PER_ROW = 4; final String TITLE = "memory dump"; // estimate initial size assuming a 2 char line separator StringWriter sw = new StringWriter(TITLE.length() + 2 + size * 2 + (size / BYTES_PER_ROW * 4)); PrintWriter out = new PrintWriter(sw); out.println(TITLE); // byte[] buf = getByteArray(offset, size); for (int i=0;i < size;i++) { // byte b = buf[i]; byte b = getByte(offset + i); if ((i % BYTES_PER_ROW) == 0) out.print("["); if (b >=0 && b < 16) out.print("0"); out.print(Integer.toHexString(b & 0xFF)); if ((i % BYTES_PER_ROW) == BYTES_PER_ROW-1 && i < size-1) out.println("]"); } if (sw.getBuffer().charAt(sw.getBuffer().length() - 2) != ']') { out.println("]"); } return sw.toString(); }
ByteOrder byteOrder=ByteOrder.nativeOrder(); for (int index=0; index < chars.length; index++, curOffset += stepSize) { byte b=lpszEnvironmentBlock.getByte(curOffset); if (asWideChars) { byte x=lpszEnvironmentBlock.getByte(curOffset + 1L); if (ByteOrder.LITTLE_ENDIAN.equals(byteOrder)) { chars[index] = (char) (((x << Byte.SIZE) & 0xFF00) | (b & 0x00FF));
public class MyFromNativeConverter implements FromNativeConverter { @Override public Object fromNative(Object nativeValue, FromNativeContext context) { DoubleNullString result = new DoubleNullString(); Pointer p = (Pointer) nativeValue; int offset = 0; List<String> doubleNullList = new ArrayList<>(); while (!(p.getByte(offset) == 0)) { String s = p.getString(offset); doubleNullList.add(s); offset += s.length() + 1; } result.lpDependencies = doubleNullList.toArray(new String[doubleNullList.size()]); return result; } @Override public Class nativeType() { return Pointer.class; } }
@Override public byte[] receive() { byte[] res = null; Pointer p = javaCanLibrary.receiveData(channelNumber, canId); int len = javaCanLibrary.getPackageSize(); if (len > 0) { if (p == null) { // System.out.println("CAN receive null pointer"); return null; } res = new byte[len]; for (int i = 0; i < len; i++) { res[i] = p.getByte(i); } javaCanLibrary.resetPackageSize(); return res; } return null; }
public ACL(Pointer pointer) { super(pointer); read(); ACEs = new ACCESS_ACEStructure[AceCount]; int offset = size(); for (int i = 0; i < AceCount; i++) { Pointer share = pointer.share(offset); // ACE_HEADER.AceType final byte aceType = share.getByte(0); ACCESS_ACEStructure ace = null; switch (aceType) { case ACCESS_ALLOWED_ACE_TYPE: ace = new ACCESS_ALLOWED_ACE(share); break; case ACCESS_DENIED_ACE_TYPE: ace = new ACCESS_DENIED_ACE(share); break; default: throw new IllegalArgumentException("Unknwon ACE type " + aceType); } ACEs[i] = ace; offset += ace.AceSize; } }
for (int i = 0; i < AceCount; i++) { final Pointer share = pointer.share(offset); final byte aceType = share.getByte(0); // ACE_HEADER.AceType switch (aceType) { case ACCESS_ALLOWED_ACE_TYPE: