public static File getTempDir() { Memory buf = new Memory(1024); if (Kernel32.INSTANCE.GetTempPathW(512,buf)!=0) {// the first arg is number of wchar return new File(buf.getString(0, true)); } else { return null; } }
public static File getTempDir() { Memory buf = new Memory(1024); if (Kernel32.INSTANCE.GetTempPathW(512,buf)!=0) {// the first arg is number of wchar return new File(buf.getString(0, true)); } else { return null; } }
public void testGetSetStringWithDefaultEncoding() throws Exception { final String ENCODING = Native.DEFAULT_ENCODING; String VALUE = getName(); int size = VALUE.getBytes(ENCODING).length+1; Memory m = new Memory(size); m.setString(0, VALUE); assertEquals("Wrong decoded value", VALUE, m.getString(0)); }
public HRESULTException(int hresult) { Memory m = new Memory(1024); Kernel32.INSTANCE.FormatMessage(Kernel32.FORMAT_MESSAGE_FROM_SYSTEM, null, hresult, 0, m, (int) m.size(), null); String mm = m.getString(0, true); mm = mm.trim(); str = String.format("HRESULT: 0x%08x [%s]", hresult, mm); }
private static void checkError(int errnum) throws DrmaaException { if (errnum != LibDrmaa.DRMAA_ERRNO.DRMAA_ERRNO_SUCCESS) checkError(errnum, getError().getString(0)); }
@Override public String getDrmaaImplementation() { Memory drmaaImplementation = new Memory(LibDrmaa.DRMAA_DRMAA_IMPLEMENTATION_BUFFER); try { checkError(LibDrmaa.drmaa_get_DRMAA_implementation(drmaaImplementation, LibDrmaa.DRMAA_DRMAA_IMPLEMENTATION_BUFFER_LEN, getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); } catch (DrmaaException e) { // DRMAA spec says this method should throw DrmaaException. // Why doesn't interface implement this? throw new RuntimeException(e); } return drmaaImplementation.getString(0); }
@Override public String getContact() { Memory contact = new Memory(LibDrmaa.DRMAA_CONTACT_BUFFER); try { checkError(LibDrmaa.drmaa_get_contact(contact, LibDrmaa.DRMAA_CONTACT_BUFFER_LEN, getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); } catch (DrmaaException e) { // DRMAA spec says this method should throw DrmaaException. // Why doesn't interface implement this? throw new RuntimeException(e); } return contact.getString(0); }
@Override public String getDrmSystem() { Memory drmSystem = new Memory(LibDrmaa.DRMAA_DRM_SYSTEM_BUFFER); try { checkError(LibDrmaa.drmaa_get_DRM_system(drmSystem, LibDrmaa.DRMAA_DRM_SYSTEM_BUFFER_LEN, getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); } catch (DrmaaException e) { // DRMAA spec says this method should throw DrmaaException. // Why doesn't interface implement this? throw new RuntimeException(e); } return drmSystem.getString(0); }
import com.sun.jna.Memory; import com.sun.jna.WString; public String winGetText(String szTitle) { Memory szRetText = new Memory(2 * 256); autoItX.AU3_WinGetText(new WString(szTitle), new WString(""), szRetText, 256); return szRetText.getString(0, true); }
public Map<zfs_prop_t,String> getZfsProperty(Collection<zfs_prop_t> props) { Memory propbuf = new Memory(libzfs.ZFS_MAXPROPLEN); char[] buf = null; IntByReference ibr = null; Hashtable<zfs_prop_t, String> map = new Hashtable<zfs_prop_t, String>(); for (zfs_prop_t prop : props) { int ret = LIBZFS.zfs_prop_get(handle, new NativeLong(prop.ordinal()), propbuf, libzfs.ZFS_MAXPROPLEN, ibr, buf, new NativeLong(0), true); if(ret==0) map.put(prop, propbuf.getString(0)); } return map; }
public Map<zfs_prop_t,String> getZfsProperty(Collection<zfs_prop_t> props) { Memory propbuf = new Memory(libzfs.ZFS_MAXPROPLEN); char[] buf = null; IntByReference ibr = null; Hashtable<zfs_prop_t, String> map = new Hashtable<zfs_prop_t, String>(); for (zfs_prop_t prop : props) { int ret = LIBZFS.zfs_prop_get(handle, new NativeLong(prop.ordinal()), propbuf, libzfs.ZFS_MAXPROPLEN, ibr, buf, new NativeLong(0), true); if(ret==0) map.put(prop, propbuf.getString(0)); } return map; }
public static String getAttribute(Pointer jt, String name) throws DrmaaException { if (getAttrNames().contains(name)) { Memory attrBuffer = new Memory(LibDrmaa.DRMAA_ATTR_BUFFER); checkError(LibDrmaa.drmaa_get_attribute(jt, name, attrBuffer, LibDrmaa.DRMAA_ATTR_BUFFER_LEN, getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); return attrBuffer.getString(0); } else { throw new InvalidAttributeValueException("Attribute " + name + " is not supported by this implementation of DRMAA"); } }
/** * String representation of the buffer. * @return * Unicode string. */ public String getString() { byte[] data = Buffer.getByteArray(0, Length); if (data.length < 2 || data[data.length - 1] != 0) { Memory newdata = new Memory(data.length + 2); newdata.write(0, data, 0, data.length); return newdata.getString(0, true); } return Buffer.getString(0, true); } }
public String getZfsProperty(zfs_prop_t prop) { Memory propbuf = new Memory(libzfs.ZFS_MAXPROPLEN); char[] buf = null; IntByReference ibr = null; int ret = LIBZFS.zfs_prop_get(handle, new NativeLong(prop.ordinal()), propbuf, libzfs.ZFS_MAXPROPLEN, ibr, buf, new NativeLong(0), true); return ((ret != 0) ? null : propbuf.getString(0)); }
@Override public String runJob(JobTemplate jobTemplate) throws DrmaaException { Memory jobId = new Memory(LibDrmaa.DRMAA_JOBNAME_BUFFER); JnaJobTemplate jnaJobTemplate = (JnaJobTemplate) jobTemplate; checkError(LibDrmaa.drmaa_run_job(jobId, LibDrmaa.DRMAA_JOBNAME_BUFFER_LEN, jnaJobTemplate.getPointer(), getError(), LibDrmaa.DRMAA_ERROR_STRING_BUFFER_LEN)); return jobId.getString(0); }
public String getZfsProperty(zfs_prop_t prop) { Memory propbuf = new Memory(libzfs.ZFS_MAXPROPLEN); char[] buf = null; IntByReference ibr = null; int ret = LIBZFS.zfs_prop_get(handle, new NativeLong(prop.ordinal()), propbuf, libzfs.ZFS_MAXPROPLEN, ibr, buf, new NativeLong(0), true); return ((ret != 0) ? null : propbuf.getString(0)); }
public String getProperty(zpool_prop_t prop) { Memory propbuf = new Memory(libzfs.ZPOOL_MAXPROPLEN); int ret = LIBZFS.zpool_get_prop(handle, new NativeLong(prop .ordinal()), propbuf, new NativeLong( libzfs.ZPOOL_MAXPROPLEN), null); return ((ret != 0) ? null : propbuf.getString(0)); }
public String getProperty(zpool_prop_t prop) { Memory propbuf = new Memory(libzfs.ZPOOL_MAXPROPLEN); int ret = LIBZFS.zpool_get_prop(handle, new NativeLong(prop .ordinal()), propbuf, new NativeLong( libzfs.ZPOOL_MAXPROPLEN), null); return ((ret != 0) ? null : propbuf.getString(0)); }
private static List<String> getAttrNames(PointerByReference names) throws DrmaaException { List<String> namesList = new ArrayList<String>(); IntByReference size = new IntByReference(); int errnum; errnum = LibDrmaa.drmaa_get_num_attr_names(names.getValue(), size); checkError(errnum, "unable to get attribute names"); int num = size.getValue(); Memory value = new Memory(LibDrmaa.DRMAA_ATTR_BUFFER); for (int i = 1; i <= num; i++) { errnum = LibDrmaa.drmaa_get_next_attr_name(names.getValue(), value, LibDrmaa.DRMAA_ATTR_BUFFER_LEN); checkError(errnum, "unable to get attribute name " + i); if (errnum == LibDrmaa.DRMAA_ERRNO.DRMAA_ERRNO_NO_MORE_ELEMENTS) break; namesList.add(value.getString(0)); } return namesList; }
synchronized public void fail() throws Fail { int err = GetLastError(); Memory buffer = new Memory(2048); int res = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, (int) buffer.size(), null); log = log && log(1, "fail() %s, Windows GetLastError()= %d, %s\n", lineno(1), err, buffer.getString(0, true)); // FIXME here convert from Windows error code to 'posix' error code Fail f = new Fail(); throw f; }