Java Code Examples for com.sun.jna.Memory#share()

The following examples show how to use com.sun.jna.Memory#share() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotesSearchKeyEncoder.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
/**
 * Writes data for a time search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param innard0 first innard of date
 * @param innard1 second innard of date
 * @throws Exception in case of errors
 */
private static void addCalendarKey(OutputStream itemOut, OutputStream valueDataOut, int innard0, int innard1) 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);
	
	Pointer timeDatePtr = valueMem.share(2);
	NotesTimeDateStruct timeDate = NotesTimeDateStruct.newInstance(timeDatePtr);
	timeDate.Innards[0] = innard0;
	timeDate.Innards[1] = innard1;
	timeDate.write();
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
Example 2
Source File: NotesSearchKeyEncoder.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
	}
}
 
Example 3
Source File: AbstractMailMergeConversion.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
@Override
	public boolean isMatch(IRichTextNavigator nav) {
		//TODO add support for search word recognition across CD record boundaries like in this JS lib: https://github.com/padolsey/findAndReplaceDOMText
		if (nav.gotoFirst()) {
			do {
				if (CDRecordType.TEXT.getConstant() == nav.getCurrentRecordTypeAsShort()) {
//					typedef struct {
//						   WSIG   Header; /* Tag and length */
//						   FONTID FontID; /* Font ID */
//						/* The 8-bit text string follows... */
//						} CDTEXT;
					Memory recordData = nav.getCurrentRecordData();
					int recordDataLength = nav.getCurrentRecordDataLength();
					int txtMemLength = recordDataLength-4;
					
					if (txtMemLength>0) {
						//skip FONTID
						Pointer txtPtr = recordData.share(4);
						String txt = NotesStringUtils.fromLMBCS(txtPtr, txtMemLength);
						
						if (containsMatch(txt)) {
							return true;
						}
					}
				}
			}
			while (nav.gotoNext());
		}
		return false;
	}
 
Example 4
Source File: NotesSearchKeyEncoder.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
	}
}
 
Example 5
Source File: NotesSearchKeyEncoder.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * Writes data for a time range search key
 * 
 * @param itemOut output stream for ITEM structure
 * @param valueDataOut output stream for search key value
 * @param startInnard0 innard 0 of startdatetime
 * @param startInnard1 innard 0 of startdatetime
 * @param endInnard0 innard 0 of enddatetime
 * @param endInnard1 innard 0 of enddatetime
 * @throws Exception in case of errors
 */
private static void addCalendarRangeKey(OutputStream itemOut, OutputStream valueDataOut, int startInnard0, int startInnard1,
		int endInnard0, int endInnard1) throws Exception {
	
	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);
	pair.Lower = NotesTimeDateStruct.newInstance(new int[] {startInnard0, startInnard1});
	pair.Upper = NotesTimeDateStruct.newInstance(new int[] {endInnard0, endInnard1});
	pair.write();
	
	for (int i=0; i<valueMem.size(); i++) {
		valueDataOut.write(valueMem.getByte(i));
	}
}
 
Example 6
Source File: NotesSearchKeyEncoder.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
	}
}
 
Example 7
Source File: AbstractMailMergeConversion.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
@Override
	public void convert(IRichTextNavigator source, ICompoundText target) {
		if (source.gotoFirst()) {
			do {
				if (CDRecordType.TEXT.getConstant() == source.getCurrentRecordTypeAsShort()) {
//					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);
					}
				}
				else {
					source.copyCurrentRecordTo(target);
				}
			}
			while (source.gotoNext());
		}
	}