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


Java Memory.getByteArray方法代码示例

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


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

示例1: convert

import com.sun.jna.Memory; //导入方法依赖的package包/类
@Override
	public void convert(IRichTextNavigator source, ICompoundText target) {
		if (source.gotoFirst()) {
			do {
				if (source.getCurrentRecordType() == CDRecordType.TEXT) {
//					typedef struct {
//						   WSIG   Header; /* Tag and length */
//						   FONTID FontID; /* Font ID */
//						/* The 8-bit text string follows... */
//						} CDTEXT;
					Memory recordData = source.getCurrentRecordData();
					int recordDataLength = source.getCurrentRecordDataLength();
					final byte[] fontIdArr = recordData.getByteArray(0, 4);
					int txtMemLength = recordDataLength-4;
					
					if (txtMemLength>0) {
						//skip FONTID
						Pointer txtPtr = recordData.share(4);
						String txt = NotesStringUtils.fromLMBCS(txtPtr, txtMemLength);
						
						if (containsMatch(txt)) {
							String newTxt = replaceAllMatches(txt);
							//add text, prevent creating extra linebreaks for newlines (false parameter)
							target.addText(newTxt, null, new FontStyle(new IAdaptable() {
								
								@Override
								public <T> T getAdapter(Class<T> clazz) {
									if (clazz==byte[].class) {
										return (T) fontIdArr;
									}
									else
										return null;
								}
							}), false);
						}
						else {
							source.copyCurrentRecordTo(target);
						}
					}
				}
				else {
					source.copyCurrentRecordTo(target);
				}
			}
			while (source.gotoNext());
		}
	}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:48,代码来源:AbstractMailMergeConversion.java

示例2: _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

示例3: 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

示例4: 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

示例5: recv

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Receives a diverted packet that matched the filter.<br>
 * The return value is a {@link com.github.ffalcinelli.jdivert.Packet packet}.
 * <p>
 * The remapped function is {@code WinDivertRecv}:
 * </p>
 * <pre>{@code
 * BOOL WinDivertRecv(
 *      __in HANDLE handle,
 *      __out PVOID pPacket,
 *      __in UINT packetLen,
 *      __out_opt PWINDIVERT_ADDRESS pAddr,
 *      __out_opt UINT *recvLen
 * );
 * }</pre>
 * <p>
 * For more info on the C call visit: <a href="http://reqrypt.org/windivert-doc.html#divert_recv">http://reqrypt.org/windivert-doc.html#divert_recv</a>
 *
 * @param bufsize The size for the buffer to allocate
 * @return A {@link com.github.ffalcinelli.jdivert.Packet Packet} instance
 * @throws WinDivertException Whenever the DLL call sets a LastError different by 0 (Success) or 997 (Overlapped I/O
 *                            is in progress)
 */
public Packet recv(int bufsize) throws WinDivertException {
    WinDivertAddress address = new WinDivertAddress();
    Memory buffer = new Memory(bufsize);
    IntByReference recvLen = new IntByReference();
    dll.WinDivertRecv(handle, buffer, bufsize, address.getPointer(), recvLen);
    throwExceptionOnGetLastError();
    byte[] raw = buffer.getByteArray(0, recvLen.getValue());
    return new Packet(raw, address);
}
 
开发者ID:ffalcinelli,项目名称:jdivert,代码行数:33,代码来源:WinDivert.java


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