当前位置: 首页>>代码示例>>Java>>正文


Java Memory.size方法代码示例

本文整理汇总了Java中com.sun.jna.Memory.size方法的典型用法代码示例。如果您正苦于以下问题:Java Memory.size方法的具体用法?Java Memory.size怎么用?Java Memory.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jna.Memory的用法示例。


在下文中一共展示了Memory.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIcon

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Gets the icon that corresponds to a given icon handler.
 * 
 * @param hIcon
 *            Handler to the icon to get
 * @return The icon that corresponds to a given icon handler
 */
public static BufferedImage getIcon(final HICON hIcon) {
	final int width = ICON_SIZE;
	final int height = ICON_SIZE;
	final short depth = ICON_DEPTH;
	final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

	final Memory lpBitsColor = new Memory(width * height * depth / ICON_BYTE_SIZE);
	final Memory lpBitsMask = new Memory(width * height * depth / ICON_BYTE_SIZE);
	final BITMAPINFO info = new BITMAPINFO();
	final BITMAPINFOHEADER hdr = new BITMAPINFOHEADER();
	info.bmiHeader = hdr;
	hdr.biWidth = width;
	hdr.biHeight = height;
	hdr.biPlanes = 1;
	hdr.biBitCount = depth;
	hdr.biCompression = WinGDI.BI_RGB;

	final HDC hDC = User32.INSTANCE.GetDC(null);
	final ICONINFO piconinfo = new ICONINFO();
	User32.INSTANCE.GetIconInfo(hIcon, piconinfo);

	GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, WinGDI.DIB_RGB_COLORS);
	GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmMask, 0, height, lpBitsMask, info, WinGDI.DIB_RGB_COLORS);

	int r, g, b, a, argb;
	int x = 0, y = height - 1;
	for (int i = 0; i < lpBitsColor.size(); i = i + 3) {
		b = lpBitsColor.getByte(i) & 0xFF;
		g = lpBitsColor.getByte(i + 1) & 0xFF;
		r = lpBitsColor.getByte(i + 2) & 0xFF;
		a = 0xFF - lpBitsMask.getByte(i) & 0xFF;

		argb = a << 24 | r << 16 | g << 8 | b;
		image.setRGB(x, y, argb);
		x = (x + 1) % width;
		if (x == 0) {
			y--;
		}
	}

	User32.INSTANCE.ReleaseDC(null, hDC);
	GDI32.INSTANCE.DeleteObject(piconinfo.hbmColor);
	GDI32.INSTANCE.DeleteObject(piconinfo.hbmMask);

	return image;
}
 
开发者ID:ZabuzaW,项目名称:Mem-Eater-Bug,代码行数:54,代码来源:User32Util.java

示例2: readVirtualMemoryToMemory

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Read virtual memory to memory.
 * 
 * @param baseAddress
 *            the base address
 * @param goal
 *            the goal
 * 
 * @return true, if successful
 */
boolean readVirtualMemoryToMemory(Pointer baseAddress, Memory goal)
{
	int size = (int) goal.size();
	// System.out.println("readVirtualMemoryToMemory "+size);
	int ret = Ntdll.INSTANCE.ZwReadVirtualMemory(
			_processInformation.hProcess.getPointer(), baseAddress, goal,
			size, null);
	if (ret != 0)
	{
		if (ret == 0x8000000d) // see more http://nologs.com/ntstatus.html
			log("pid " + _pid + " ZwReadVirtualMemory returns "
					+ Integer.toHexString(ret) + " partial copy ");
		else
			log("pid " + _pid + " ZwReadVirtualMemory returns "
					+ Integer.toHexString(ret));
	}

	return ret == 0;

}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:31,代码来源:WindowsXPProcess.java

示例3: getCurrentUsername

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * This function returns the Username associated with the workstation's or server's ID where this function is executed.<br>
 * 
 * @return username
 */
public static String getCurrentUsername() {
	Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1);
	
	short result = NotesNativeAPI.get().SECKFMGetUserName(retUserNameMem);
	NotesErrorUtils.checkResult(result);
	
	int userNameLength = 0;
	for (int i=0; i<retUserNameMem.size(); i++) {
		userNameLength = i;
		if (retUserNameMem.getByte(i) == 0) {
			break;
		}
	}
	
	String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength);
	return userName;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:23,代码来源:IDUtils.java

示例4: switchToId

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * This function switches to the specified ID file and returns the user name associated with it.<br>
 * <br>
 * Multiple passwords are not supported.<br>
 * <br>
 * NOTE: This function should only be used in a C API stand alone application.
 * 
 * @param idPath path to the ID file that is to be switched to
 * @param password password of the ID file that is to be switched to
 * @param dontSetEnvVar  If specified, the notes.ini file (either ServerKeyFileName or KeyFileName) is modified to reflect the ID change.
 * @return user name, in the ID file that is to be switched to
 */
public static String switchToId(String idPath, String password, boolean dontSetEnvVar) {
	Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
	Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
	Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1);
	
	short result = NotesNativeAPI.get().SECKFMSwitchToIDFile(idPathMem, passwordMem, retUserNameMem,
			NotesConstants.MAXUSERNAME, dontSetEnvVar ? NotesConstants.fKFM_switchid_DontSetEnvVar : 0, null);
	NotesErrorUtils.checkResult(result);
	
	int userNameLength = 0;
	for (int i=0; i<retUserNameMem.size(); i++) {
		userNameLength = i;
		if (retUserNameMem.getByte(i) == 0) {
			break;
		}
	}
	
	String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength);
	return userName;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:33,代码来源:IDUtils.java

示例5: addNumberKey

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Writes data for a number search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param doubleValue search key
 * @throws Exception in case of errors
 */
private static void addNumberKey(OutputStream itemOut, OutputStream valueDataOut, double doubleValue) throws Exception {
	Memory itemMem = new Memory(NotesConstants.tableItemSize);
	NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem);
	item.NameLength = 0;
	item.ValueLength = (short) (8 + 2);
	item.write();

	for (int i=0; i<NotesConstants.tableItemSize; i++) {
		itemOut.write(itemMem.getByte(i));
	}

	Memory valueMem = new Memory(8 + 2);
	valueMem.setShort(0, (short) NotesItem.TYPE_NUMBER);
	
	Pointer doubleValPtr = valueMem.share(2);
	doubleValPtr.setDouble(0, doubleValue);
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:30,代码来源:NotesSearchKeyEncoder.java

示例6: readProcessMemory

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * readProcessMemory to memory.
 */
long readProcessMemory(Pointer baseAddress, Memory goal)
{
	NativeLong sizeAvalaible = new NativeLong(goal.size());
	NativeLongByReference bytesReadRefernce = new NativeLongByReference();
	boolean ret = MyKernel32.INSTANCE.ReadProcessMemory(
			_processInformation.hProcess.getPointer(), baseAddress, goal,
			sizeAvalaible, bytesReadRefernce);
	if (!ret)
		log("pid " + _pid + " ReadProcessMemory returns " + ret);
	long bytesRead = bytesReadRefernce.getValue().longValue();
	return bytesRead;

}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:17,代码来源:WindowsXPProcess.java

示例7: getNullTerminatedLength

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Scans the Memory object for null values
 * 
 * @param in memory
 * @return number of bytes before null byte in memory
 */
public static int getNullTerminatedLength(Memory in) {
	int textLen = (int) in.size();
	
	//search for terminating null character
	for (int i=0; i<textLen; i++) {
		byte b = in.getByte(i);
		if (b==0) {
			textLen = i;
			break;
		}
	}

	return textLen;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:21,代码来源:NotesStringUtils.java

示例8: ReadOnlyMemory

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Creates a new instance
 * 
 * @param wrappedMemory writable Memory that we want to wrap to prevent data changes
 */
public ReadOnlyMemory(Memory wrappedMemory) {
	super();
	this.peer = Memory.nativeValue(wrappedMemory);
	this.size = wrappedMemory.size();
	//keep reference on original memory to prevent GC
	m_wrappedMemory = wrappedMemory;
	m_sealed = true;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:14,代码来源:ReadOnlyMemory.java

示例9: addCalendarKey

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Writes data for a time search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param currKey search key
 * @throws Exception in case of errors
 */
private static void addCalendarKey(OutputStream itemOut, OutputStream valueDataOut, Calendar currKey) throws Exception {
	Memory itemMem = new Memory(NotesConstants.tableItemSize);
	NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem);
	item.NameLength = 0;
	item.ValueLength = (short) (NotesConstants.timeDateSize + 2);
	item.write();
	
	for (int i=0; i<NotesConstants.tableItemSize; i++) {
		itemOut.write(itemMem.getByte(i));
	}
	
	//write data type
	Memory valueMem = new Memory(2 + 8);
	valueMem.setShort(0, (short) NotesItem.TYPE_TIME);
	
	boolean hasDate = NotesDateTimeUtils.hasDate(currKey);
	boolean hasTime = NotesDateTimeUtils.hasTime(currKey);
	
	int[] innards = NotesDateTimeUtils.calendarToInnards(currKey, hasDate, hasTime);
	Pointer timeDatePtr = valueMem.share(2);
	NotesTimeDateStruct timeDate = NotesTimeDateStruct.newInstance(timeDatePtr);
	timeDate.Innards[0] = innards[0];
	timeDate.Innards[1] = innards[1];
	timeDate.write();
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:38,代码来源:NotesSearchKeyEncoder.java

示例10: addNumberRangeKey

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Searching with number range keys is not supported yet (R9), as the 
 * <a href="http://www-12.lotus.com/ldd/doc/domino_notes/9.0/api90ref.nsf/70cfe734675fd140852561ce00718042/35abe18f9580ca2d8525622e0062c48d?OpenDocument">documentation</a> says.
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param currKey search key
 * @throws Exception in case of errors
 */
private static void addNumberRangeKey(OutputStream itemOut, OutputStream valueDataOut, double[] currKey) throws Exception {
	if (currKey.length!=2)
		throw new IllegalArgumentException("Double search key array must have exactly 2 elements. We found "+currKey.length);
	
	Memory itemMem = new Memory(NotesConstants.tableItemSize);
	NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem);
	item.NameLength = 0;
	item.ValueLength = (short) ((NotesConstants.rangeSize + NotesConstants.numberPairSize + 2) & 0xffff);
	item.write();

	for (int i=0; i<NotesConstants.tableItemSize; i++) {
		itemOut.write(itemMem.getByte(i));
	}

	Memory valueMem = new Memory(NotesConstants.rangeSize + NotesConstants.numberPairSize + 2);
	valueMem.setShort(0, (short) NotesItem.TYPE_NUMBER_RANGE);

	Pointer rangePtr = valueMem.share(2);
	NotesRangeStruct range = NotesRangeStruct.newInstance(rangePtr);
	range.ListEntries = 0;
	range.RangeEntries = 1;
	range.write();

	Pointer pairPtr = rangePtr.share(NotesConstants.rangeSize);
	NotesNumberPairStruct pair = NotesNumberPairStruct.newInstance(pairPtr);
	pair.Lower = currKey[0];
	pair.Upper = currKey[1];
	pair.write();
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:43,代码来源:NotesSearchKeyEncoder.java

示例11: addCalendarRangeKey

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Writes data for a time range search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param currKey search key, array with two values
 * @throws Exception in case of errors
 */
private static void addCalendarRangeKey(OutputStream itemOut, OutputStream valueDataOut, Calendar[] currKey) throws Exception {
	if (currKey.length!=2)
		throw new IllegalArgumentException("Calendar search key array must have exactly 2 elements. We found "+currKey.length);
	
	Memory itemMem = new Memory(NotesConstants.tableItemSize);
	NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem);
	item.NameLength = 0;
	item.ValueLength = (short) ((NotesConstants.rangeSize + NotesConstants.timeDatePairSize + 2) & 0xffff);
	item.write();

	for (int i=0; i<NotesConstants.tableItemSize; i++) {
		itemOut.write(itemMem.getByte(i));
	}

	Memory valueMem = new Memory(NotesConstants.rangeSize + NotesConstants.timeDatePairSize + 2);
	valueMem.setShort(0, (short) NotesItem.TYPE_TIME_RANGE);
	
	Pointer rangePtr = valueMem.share(2);
	NotesRangeStruct range = NotesRangeStruct.newInstance(rangePtr);
	range.ListEntries = 0;
	range.RangeEntries = 1;
	range.write();
	
	Pointer pairPtr = rangePtr.share(NotesConstants.rangeSize);
	NotesTimeDatePairStruct pair = NotesTimeDatePairStruct.newInstance(pairPtr);
	Calendar lowerBound = currKey[0];
	Calendar upperBound = currKey[1];
	NotesTimeDate lower = NotesDateTimeUtils.calendarToTimeDate(lowerBound);
	NotesTimeDate upper = NotesDateTimeUtils.calendarToTimeDate(upperBound);
	
	pair.Lower = lower.getAdapter(NotesTimeDateStruct.class);
	pair.Upper = upper.getAdapter(NotesTimeDateStruct.class);
	pair.write();
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:47,代码来源:NotesSearchKeyEncoder.java

示例12: addStringKey

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Writes data for a string search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param currKey search key
 * @throws Exception in case of errors
 */
private static void addStringKey(OutputStream itemOut, OutputStream valueDataOut, String currKey) throws Exception {
	Memory strValueMem = NotesStringUtils.toLMBCS(currKey, false);
	
	Memory itemMem = new Memory(NotesConstants.tableItemSize);
	NotesTableItemStruct item = NotesTableItemStruct.newInstance(itemMem);
	item.NameLength = 0;
	item.ValueLength = (short) ((strValueMem.size() + 2) & 0xffff);
	item.write();

	for (int i=0; i<NotesConstants.tableItemSize; i++) {
		itemOut.write(itemMem.getByte(i));
	}

	Memory valueMem = new Memory(strValueMem.size() + 2);
	short txtType = (short) NotesItem.TYPE_TEXT;
	valueMem.setShort(0, txtType);

	Pointer strValuePtr = valueMem.share(2);
	
	for (int i=0; i<strValueMem.size(); i++) {
		strValuePtr.setByte(i, strValueMem.getByte(i));
	}
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:36,代码来源:NotesSearchKeyEncoder.java

示例13: _getUserIdFromVault

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Internal helper method to fetch the ID from the ID vault.
 * 
 * @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
 * @param password Password to id file being uploaded to the vault
 * @param idPath if not null, path to where the download ID file should be created or overwritten
 * @param rethKFC64 if not null, returns the hKFC handle to the in-memory id for 64 bit
 * @param rethKFC32 if not null, returns the hKFC handle to the in-memory id for 32 bit
 * @param serverName Name of server to contact
 * @return the vault server name
 * @throws NotesError in case of problems, e.g. ERR 22792 Wrong Password
 */
private static String _getUserIdFromVault(String userName, String password, String idPath, LongByReference rethKFC64, IntByReference rethKFC32, String serverName) {
	String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
	Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
	Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
	Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
	Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
	{
		Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
		if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
			throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
		}
		if (serverNameParamMem!=null) {
			byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
			serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
		}
		else {
			serverNameMem.setByte(0, (byte) 0);
		}
	}
	
	short result;
	if (PlatformUtils.is64Bit()) {
		result = NotesNativeAPI64.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC64, serverNameMem, 0, (short) 0, null);
	}
	else {
		result = NotesNativeAPI32.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC32, serverNameMem, 0, (short) 0, null);
	}
	NotesErrorUtils.checkResult(result);
	
	int vaultServerNameLength = 0;
	for (int i=0; i<serverNameMem.size(); i++) {
		vaultServerNameLength = i;
		if (serverNameMem.getByte(i) == 0) {
			break;
		}
	}
	
	String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
	return vaultServerName;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:53,代码来源:IDUtils.java

示例14: syncUserIdWithVault

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Will open the ID file name provided, locate a vault server, synch the ID file contents to the vault,
 * then return the synched content. If successful the vault server name is returned.

 * @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
 * @param password Password to id file being uploaded to the vault
 * @param idPath Path to where the download ID file should be created or overwritten
 * @param serverName Name of server to contact
 * @return sync result
 */
public static SyncResult syncUserIdWithVault(String userName, String password, String idPath, String serverName) {
	String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
	Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
	Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
	Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
	Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
	{
		Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
		if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
			throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
		}
		if (serverNameParamMem!=null) {
			byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
			serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
		}
		else {
			serverNameMem.setByte(0, (byte) 0);
		}
	}
	
	LongByReference phKFC64 = new LongByReference();
	IntByReference phKFC32 = new IntByReference();
	IntByReference retdwFlags = new IntByReference();
	
	short result;
	if (PlatformUtils.is64Bit()) {
		result = NotesNativeAPI64.get().SECKFMOpen (phKFC64, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
	}
	else {
		result = NotesNativeAPI32.get().SECKFMOpen (phKFC32, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
	}
	NotesErrorUtils.checkResult(result);
	
	try {
		if (PlatformUtils.is64Bit()) {
			result = NotesNativeAPI64.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC64, serverNameMem, 0, (short) 0, null, retdwFlags);
		}
		else {
			result = NotesNativeAPI32.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC32, serverNameMem, 0, (short) 0, null, retdwFlags);
		}
		NotesErrorUtils.checkResult(result);
	}
	finally {
		if (PlatformUtils.is64Bit()) {
			result = NotesNativeAPI64.get().SECKFMClose(phKFC64, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
		}
		else {
			result = NotesNativeAPI32.get().SECKFMClose(phKFC32, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
		}
		NotesErrorUtils.checkResult(result);
	}

	NotesErrorUtils.checkResult(result);
	
	int vaultServerNameLength = 0;
	for (int i=0; i<serverNameMem.size(); i++) {
		vaultServerNameLength = i;
		if (serverNameMem.getByte(i) == 0) {
			break;
		}
	}
	
	String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
	
	SyncResult syncResult = new SyncResult(vaultServerName, retdwFlags.getValue());
	return syncResult;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:78,代码来源:IDUtils.java

示例15: constructNetPath

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Constructs a network path of a database (server!!path with proper encoding)
 * 
 * @param server server or null
 * @param filePath filepath
 * @return LMBCS encoded path
 */
private static Memory constructNetPath(String server, String filePath) {
	if (server==null)
		server = "";
	if (filePath==null)
		throw new NullPointerException("filePath is null");

	server = NotesNamingUtils.toCanonicalName(server);
	
	String idUserName = IDUtils.getCurrentUsername();
	boolean isOnServer = IDUtils.isOnServer();
	
	if (!"".equals(server)) {
		if (isOnServer) {
			String serverCN = NotesNamingUtils.toCommonName(server);
			String currServerCN = NotesNamingUtils.toCommonName(idUserName);
			if (serverCN.equalsIgnoreCase(currServerCN)) {
				//switch to "" as servername if server points to the server the API is running on
				server = "";
			}
		}
	}
	
	Memory dbServerLMBCS = NotesStringUtils.toLMBCS(server, true);
	Memory dbFilePathLMBCS = NotesStringUtils.toLMBCS(filePath, true);
	Memory retFullNetPath = new Memory(NotesConstants.MAXPATH);

	short result = NotesNativeAPI.get().OSPathNetConstruct(null, dbServerLMBCS, dbFilePathLMBCS, retFullNetPath);
	NotesErrorUtils.checkResult(result);

	//reduce length of retDbPathName
	int newLength = 0;
	for (int i=0; i<retFullNetPath.size(); i++) {
		byte b = retFullNetPath.getByte(i);
		if (b==0) {
			newLength = i;
			break;
		}
	}
	byte[] retFullNetPathArr = retFullNetPath.getByteArray(0, newLength);
	
	Memory reducedFullNetPathMem = new Memory(newLength+1);
	reducedFullNetPathMem.write(0, retFullNetPathArr, 0, retFullNetPathArr.length);
	reducedFullNetPathMem.setByte(newLength, (byte) 0);
	return reducedFullNetPathMem;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:53,代码来源:NotesDatabase.java


注:本文中的com.sun.jna.Memory.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。