/** * Turn on the keyboard overlay. This is a keyboard that hovers in front of the user, that can be typed upon by * pointing the ray extending from the top of the controller at the key the user wants to press. * @param showingState - true or false * @return - true if successful. If this call fails, an error is logged. */ public static boolean setKeyboardOverlayShowing(boolean showingState) { int ret; if (showingState) { Pointer pointer = new Memory(3); pointer.setString(0, "mc"); Pointer empty = new Memory(1); empty.setString(0, ""); ret = vrOverlay.ShowKeyboard.apply(0, 0, pointer, 256, empty, (byte) 1, 0); keyboardShowing = 0 == ret; //0 = no error, > 0 see EVROverlayError if (ret != 0) { logger.error("VR Overlay Error: " + vrOverlay.GetOverlayErrorNameFromEnum.apply(ret).getString(0)); } } else { try { vrOverlay.HideKeyboard.apply(); } catch (Error e) { logger.error("Error bringing up keyboard overlay: " + e.toString()); } keyboardShowing = false; } return keyboardShowing; }
private static int windowsPing(World world) throws UnknownHostException { IPHlpAPI ipHlpAPI = IPHlpAPI.INSTANCE; Pointer ptr = ipHlpAPI.IcmpCreateFile(); InetAddress inetAddress = InetAddress.getByName(world.getAddress()); byte[] address = inetAddress.getAddress(); String dataStr = RUNELITE_PING; int dataLength = dataStr.length() + 1; Pointer data = new Memory(dataLength); data.setString(0L, dataStr); IcmpEchoReply icmpEchoReply = new IcmpEchoReply(new Memory(IcmpEchoReply.SIZE + dataLength)); assert icmpEchoReply.size() == IcmpEchoReply.SIZE; int packed = (address[0] & 0xff) | ((address[1] & 0xff) << 8) | ((address[2] & 0xff) << 16) | ((address[3] & 0xff) << 24); int ret = ipHlpAPI.IcmpSendEcho(ptr, packed, data, (short) (dataLength), Pointer.NULL, icmpEchoReply, IcmpEchoReply.SIZE + dataLength, TIMEOUT); if (ret != 1) { ipHlpAPI.IcmpCloseHandle(ptr); return -1; } int rtt = Math.toIntExact(icmpEchoReply.roundTripTime.longValue()); ipHlpAPI.IcmpCloseHandle(ptr); return rtt; }
/** * Copy bytes out of string <code>value</code> to the location being * pointed to, using the encoding indicated by {@link * Native#getDefaultStringEncoding()}. * * @param offset byte offset from pointer at which characters in * <code>value</code> must be set * @param value <code>java.lang.String</code> value to set */ public void setString(long offset, String value) { setString(offset, value, Native.getDefaultStringEncoding()); }
@Override public void setString(long offset, String value, String encoding) { boundsCheck(offset, Native.getBytes(value, encoding).length + 1L); super.setString(offset, value, encoding); }
Pointer m = new Memory( new_value.length() + 1 ); //assumes ASCII m.setString( 0, new_value ); int result = lib.gp_widget_set_value( widget, m );
static void setConsumer( Pointer ptr , int offset , String consumer ) { if ( consumer.length() > 31 ) { throw new IllegalArgumentException( "Consumer length must be < 32" ) ; } ptr.setString( offset , consumer ) ; } }
/** * Copy bytes out of string <code>value</code> to the location being * pointed to, using the encoding indicated by {@link * Native#getDefaultStringEncoding()}. * * @param offset byte offset from pointer at which characters in * <code>value</code> must be set * @param value <code>java.lang.String</code> value to set */ public void setString(long offset, String value) { setString(offset, value, Native.getDefaultStringEncoding()); }
public void setValue(String value) { this.getPointer().setString(0, value); }
public void setValue(String value) { this.getPointer().setString(0, value, true); }
public static Pointer pointerFrom(String string) { Pointer pointer = new Memory(Native.WCHAR_SIZE * (string.length() + 1)); pointer.setString(0L, string); return pointer; }
public void setValue(String value) { getPointer().setString(0, value); }
String myString = "CURRENT_USER"; Pointer m = new Memory(myString.length() + 1); // WARNING: assumes ascii-only string m.setString(0, myString);
/** * Copy string <code>value</code> to the location being pointed to. * * @param offset byte offset from pointer at which characters in * <code>value</code> must be set * @param value <code>java.lang.String</code> value to set * @param wide whether to write the native string as an array of * <code>wchar_t</code>. If false, writes as a NUL-terminated array of * <code>char</code> using the encoding indicated by {@link * Native#getDefaultStringEncoding()}. * * @deprecated use {@link #setWideString(long,String)} instead. */ @Deprecated public void setString(long offset, String value, boolean wide) { if (wide) { setWideString(offset, value); } else { setString(offset, value); } }
public int callback(Pointer caller_handle, Pointer buf, int len) { // retrieve encoding, if no ghost4j encoding defined = use // JVM default String encoding = System.getProperty( PROPERTY_NAME_ENCODING, System.getProperty("file.encoding")); try { byte[] buffer = new byte[1000]; int read = getStdIn().read(buffer); if (read != -1) { buf.setString(0, new String(buffer, 0, read, encoding)); buffer = null; return read; } } catch (Exception e) { // an error occurs: do nothing } return 0; } };
/** * Indirect the native pointer to <code>malloc</code> space, a la * <code>Pointer.setString</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#setString(long,String,boolean) */ public void setString(long offset, String value, boolean wide) { if (wide) boundsCheck(offset, (value.length() + 1) * Native.WCHAR_SIZE); else boundsCheck(offset, value.getBytes().length + 1); super.setString(offset, value, wide); }
RenderModel_t.ByReference modelPtr = new RenderModel_t.ByReference(); if (errorBuffer.get(0) != VR.EVRRenderModelError.VRRenderModelError_None) { return null; } int error; PointerByReference modelPtrPtr = new PointerByReference(modelPtr.getPointer()); while (true) { Pointer stringPointer = new Memory(modelName.length() + 1); stringPointer.setString(0, modelName); error = renderModels.LoadRenderModel_Async.apply(stringPointer, modelPtrPtr); if (error != VR.EVRRenderModelError.VRRenderModelError_Loading) { break; } try { Thread.sleep(1); } catch (InterruptedException ex) { Logger.getLogger(ModelsRender.class.getName()).log(Level.SEVERE, null, ex); } } RenderModel_t model = new RenderModel_t(modelPtrPtr.getValue()); model.read();
@Override public void setString(long offset, String value, String encoding) { boundsCheck(offset, Native.getBytes(value, encoding).length + 1L); super.setString(offset, value, encoding); }
/** Create a native string as a NUL-terminated array of <code>wchar_t</code> * (if <code>wide</code> is true) or <code>char</code>.<p> * If the system property <code>jna.encoding</code> is set, its value will * be used to encode the native <code>char</code>string. * If not set or if the encoding is unavailable, the default platform * encoding will be used. * * @param string value to write to native memory * @param wide whether to store the String as <code>wchar_t</code> */ public NativeString(String string, boolean wide) { this.value = string; if (string == null) { throw new NullPointerException("String must not be null"); } // Allocate the memory to hold the string. Note, we have to // make this 1 element longer in order to accommodate the terminating // NUL (which is generated in Pointer.setString()). if (wide) { int len = (string.length() + 1 ) * Native.WCHAR_SIZE; pointer = new Memory(len); pointer.setString(0, string, true); } else { byte[] data = Native.getBytes(string); pointer = new Memory(data.length + 1); pointer.setString(0, string); } }
int len = (string.length() + 1 ) * Native.WCHAR_SIZE; pointer = new Memory(len); pointer.setString(0, string, true);
size = string.length() + 1; pointer = new Memory( size ); pointer.setString( 0, string ); break;