Java Code Examples for com.sun.jna.Memory

The following examples show how to use com.sun.jna.Memory. These examples are extracted from open source projects. 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 Project: jnanomsg   Source File: Poller.java    License: Apache License 2.0 6 votes vote down vote up
public void register(Socket socket, int flags) {
  int pos = this.next;
  this.next += EVENT_SIZE;

  if (pos > this.items.size()) {
    final long newSize = this.items.size() + (EVENT_SIZE * SIZE_INCREMENT);
    final Memory newItems = new Memory(newSize);

    for(int i=0; i<this.items.size(); i++) {
      newItems.setByte(i, this.items.getByte(i));
    }
  }

  final int socketFd = socket.getFd();
  final NNPollEvent.ByReference event = new NNPollEvent.ByReference();
  event.reuse(this.items, pos);
  event.fd = socketFd;
  event.events = (short)flags;
  event.write();

  this.offsetMap.put(socketFd, pos);
}
 
Example 2
Source Project: domino-jna   Source File: MessageQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method to test whether a queue with a specified name exists (tries to open the queue)
 * 
 * @param queueName queue name
 * @return true if queue exists
 */
public static boolean hasQueue(String queueName) {
	Memory queueNameMem = NotesStringUtils.toLMBCS(queueName, true);

	IntByReference retQueue = new IntByReference();
	short result = NotesNativeAPI.get().MQOpen(queueNameMem, 0, retQueue);
	if (result==INotesErrorConstants.ERR_NO_SUCH_MQ) {
		return false;
	}
	else if (result==0) {
		result = NotesNativeAPI.get().MQClose(retQueue.getValue(), 0);
		NotesErrorUtils.checkResult(result);
		return true;
	}
	else {
		NotesErrorUtils.checkResult(result);
		return false;
	}
}
 
Example 3
Source Project: domino-jna   Source File: MessageQueue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a message queue with the specified name.
 * 
 * @param queueName name to be assigned to the message queue
 * @param quota Maximum number of messages that the queue may contain. Set this to zero for the default maximum. The default maximum number of messages that the queue may contain is MAXWORD.
 * @param noRecycle true to exclude the queue from auto GC so that it can be used later on by other processes
 * @return queue
 */
public static MessageQueue createAndOpen(String queueName, int quota, boolean noRecycle) {
	Memory queueNameMem = NotesStringUtils.toLMBCS(queueName, true);

	short result = NotesNativeAPI.get().MQCreate(queueNameMem, (short) (quota & 0xffff), 0);
	NotesErrorUtils.checkResult(result);

	IntByReference retQueue = new IntByReference();
	result = NotesNativeAPI.get().MQOpen(queueNameMem, 0, retQueue);
	NotesErrorUtils.checkResult(result);

	MessageQueue queue = new MessageQueue(queueName, retQueue.getValue());
	if (!noRecycle) {
		NotesGC.__objectCreated(MessageQueue.class, queue);
	}
	return queue;
}
 
Example 4
Source Project: consulo   Source File: JnaUnixMediatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FileAttributes getAttributes(@Nonnull String path) {
  Memory buffer = new Memory(256);
  int res = SystemInfo.isLinux ? myLibC.__lxstat64(STAT_VER, path, buffer) : myLibC.lstat(path, buffer);
  if (res != 0) return null;

  int mode = getModeFlags(buffer) & LibC.S_MASK;
  boolean isSymlink = (mode & LibC.S_IFMT) == LibC.S_IFLNK;
  if (isSymlink) {
    if (!loadFileStatus(path, buffer)) {
      return FileAttributes.BROKEN_SYMLINK;
    }
    mode = getModeFlags(buffer) & LibC.S_MASK;
  }

  boolean isDirectory = (mode & LibC.S_IFMT) == LibC.S_IFDIR;
  boolean isSpecial = !isDirectory && (mode & LibC.S_IFMT) != LibC.S_IFREG;
  long size = buffer.getLong(myOffsets[OFF_SIZE]);
  long mTime1 = SystemInfo.is32Bit ? buffer.getInt(myOffsets[OFF_TIME]) : buffer.getLong(myOffsets[OFF_TIME]);
  long mTime2 = myCoarseTs ? 0 : SystemInfo.is32Bit ? buffer.getInt(myOffsets[OFF_TIME] + 4) : buffer.getLong(myOffsets[OFF_TIME] + 8);
  long mTime = mTime1 * 1000 + mTime2 / 1000000;

  boolean writable = ownFile(buffer) ? (mode & LibC.WRITE_MASK) != 0 : myLibC.access(path, LibC.W_OK) == 0;

  return new FileAttributes(isDirectory, isSpecial, isSymlink, false, size, mTime, writable);
}
 
Example 5
Source Project: domino-jna   Source File: NotesStringUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
	if (in == null) {
		return 0;
	}
	
	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;
}
 
Example 6
Source Project: domino-jna   Source File: NotesStringUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Given a fully-qualified network path to a Domino database file, this function breaks it
 * into its port name, server name, and filename components.<br>
 * If the fully qualified path contains just the port name and/or server name components,
 * then they will be the only ones returned.<br>
 * <br>
 * Expanded database filepath syntax:<br>
 * <br>
 * {Port} NetworkSeparator {servername} Serversuffix {filename}<br>
 * COM! {NetworkSeparator} NOTESBETA {ServerSuffix} NOTEFILE\APICOMMS.NSF<br>
 * <br>
 * Note: the NetworkSeparator and ServerSuffix are not system independent. To maintain the
 * portability of your code, it is recommended that you make no explicit use of them
 * anywhere in your programs.
 * 
 * @param pathName expanded path specification of a Domino database file
 * @return String array of portname, servername, filename
 */
public static String[] osPathNetParse(String pathName) {
	DisposableMemory retPortNameMem = new DisposableMemory(NotesConstants.MAXPATH);
	DisposableMemory retServerNameMem = new DisposableMemory(NotesConstants.MAXPATH);
	DisposableMemory retFileNameMem = new DisposableMemory(NotesConstants.MAXPATH);
	
	Memory pathNameMem = toLMBCS(pathName, true);
	short result = NotesNativeAPI.get().OSPathNetParse(pathNameMem, retPortNameMem, retServerNameMem, retFileNameMem);
	NotesErrorUtils.checkResult(result);
	
	String portName = fromLMBCS(retPortNameMem, getNullTerminatedLength(retPortNameMem));
	String serverName = fromLMBCS(retServerNameMem, getNullTerminatedLength(retServerNameMem));
	String fileName = fromLMBCS(retFileNameMem, getNullTerminatedLength(retFileNameMem));
	
	retPortNameMem.dispose();
	retServerNameMem.dispose();
	retFileNameMem.dispose();
	
	return new String[] {portName, serverName, fileName};
}
 
Example 7
Source Project: domino-jna   Source File: NotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public native short NSFDbGetNotes(
int hDB,
int NumNotes,
Memory NoteID, //NOTEID array
Memory NoteOpenFlags, // DWORD array
Memory SinceSeqNum, // DWORD array
int ControlFlags,
int hObjectDB,
Pointer CallbackParam,
NotesCallbacks.NSFGetNotesCallback  GetNotesCallback,
NotesCallbacks.b32_NSFNoteOpenCallback  NoteOpenCallback,
NotesCallbacks.b32_NSFObjectAllocCallback  ObjectAllocCallback,
NotesCallbacks.b32_NSFObjectWriteCallback  ObjectWriteCallback,
NotesTimeDateStruct FolderSinceTime,
NotesCallbacks.NSFFolderAddCallback  FolderAddCallback);
 
Example 8
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFDbGetNotes(
int hDB,
int NumNotes,
Memory NoteID, //NOTEID array
Memory NoteOpenFlags, // DWORD array
Memory SinceSeqNum, // DWORD array
int ControlFlags,
int hObjectDB,
Pointer CallbackParam,
NotesCallbacks.NSFGetNotesCallback  GetNotesCallback,
NotesCallbacks.b32_NSFNoteOpenCallback  NoteOpenCallback,
NotesCallbacks.b32_NSFObjectAllocCallback  ObjectAllocCallback,
NotesCallbacks.b32_NSFObjectWriteCallback  ObjectWriteCallback,
NotesTimeDateStruct FolderSinceTime,
NotesCallbacks.NSFFolderAddCallback  FolderAddCallback);
 
Example 9
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFMimePartCreateStream(
int hNote,
Memory pchItemName,
short wItemNameLen,
short wPartType,
int dwFlags,
IntByReference phCtx);
 
Example 10
Source Project: netbeans   Source File: MacNetworkProxy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts CFString object to String.
 * 
 * @param cfStringPointer Pointer to CFString object
 * @return String from CFString
 */
private String getStringFromCFStringRef(Pointer cfStringPointer) {
    if (cfStringPointer != null) {
        long lenght = cfLibrary.CFStringGetLength(cfStringPointer);
        long maxSize = cfLibrary.CFStringGetMaximumSizeForEncoding(lenght, 0x08000100); // 0x08000100 = UTF-8

        Pointer buffer = new Memory(maxSize);

        if (cfLibrary.CFStringGetCString(cfStringPointer, buffer, maxSize, 0x08000100)) { // 0x08000100 = UTF-8
            return buffer.getString(0L);
        }
    }
    
    return null;
}
 
Example 11
protected static void write(int level, String message, UnixSyslogConfig config) throws SyslogRuntimeException {
    synchronized (libraryInstance) {
        if (currentFacility != config.getFacility()) {
            if (openlogCalled) {
                libraryInstance.closelog();
                openlogCalled = false;
            }

            currentFacility = config.getFacility();
        }

        if (!openlogCalled) {
            String ident = config.getIdent();

            if (ident != null && "".equals(ident.trim())) {
                ident = null;
            }

            if (ident != null) {
                identBuffer = new Memory(128);
                identBuffer.setString(0, ident, false);
            }

            libraryInstance.openlog(identBuffer, config.getOption(), currentFacility);
            openlogCalled = true;
        }

        int priority = currentFacility | level;

        libraryInstance.syslog(priority, "%s", message);
    }
}
 
Example 12
Source Project: ev3dev-lang-java   Source File: EmulatedFramebuffer.java    License: MIT License 5 votes vote down vote up
EmulatedFramebuffer(BufferedImage buffer,
                    fb_fix_screeninfo fixinfo,
                    fb_var_screeninfo varinfo,
                    HashMap<Integer, Integer> con2fb) {
    this.imageView = buffer;
    this.fixinfo = fixinfo;
    this.varinfo = varinfo;
    this.con2fb = con2fb;
    this.memory = new Memory(bufferSize());
    this.fixinfo.smem_start = new NativeLong(Pointer.nativeValue(this.memory));
    this.fixinfo.mmio_start = new NativeLong(Pointer.nativeValue(this.memory));
    this.snapshots = new LinkedList<>();
    resetCount();
}
 
Example 13
Source Project: domino-jna   Source File: INotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public void NSFItemQueryEx(
long  note_handle,
NotesBlockIdStruct.ByValue item_bid,
Memory item_name,
short  return_buf_len,
ShortByReference name_len_ptr,
ShortByReference item_flags_ptr,
ShortByReference value_datatype_ptr,
NotesBlockIdStruct value_bid_ptr,
IntByReference value_len_ptr,
ByteByReference retSeqByte,
ByteByReference retDupItemID);
 
Example 14
Source Project: domino-jna   Source File: INotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFMimePartCreateStream(
long hNote,
Memory pchItemName,
short wItemNameLen,
short wPartType,
int dwFlags,
LongByReference phCtx);
 
Example 15
Source Project: domino-jna   Source File: ItemDecoder.java    License: Apache License 2.0 5 votes vote down vote up
public static List<Object> decodeTextListValue(Pointer ptr, boolean convertStringsLazily) {
	//read a text list item value
	int listCountAsInt = ptr.getShort(0) & 0xffff;
	
	List<Object> listValues = new ArrayList<Object>(listCountAsInt);
	
	Memory retTextPointer = new Memory(Native.POINTER_SIZE);
	ShortByReference retTextLength = new ShortByReference();
	
	for (short l=0; l<listCountAsInt; l++) {
		short result = NotesNativeAPI.get().ListGetText(ptr, false, l, retTextPointer, retTextLength);
		NotesErrorUtils.checkResult(result);
		
		//retTextPointer[0] points to the list entry text
		Pointer pointerToTextInMem = retTextPointer.getPointer(0);
		int retTextLengthAsInt = retTextLength.getValue() & 0xffff;
		
		if (retTextLengthAsInt==0) {
			listValues.add("");
		}
		else {
			if (convertStringsLazily) {
				byte[] stringDataArr = new byte[retTextLengthAsInt];
				pointerToTextInMem.read(0, stringDataArr, 0, retTextLengthAsInt);

				LMBCSString lmbcsString = new LMBCSString(stringDataArr);
				listValues.add(lmbcsString);
			}
			else {
				String currListEntry = NotesStringUtils.fromLMBCS(pointerToTextInMem, (short) retTextLengthAsInt);
				listValues.add(currListEntry);
			}
		}
	}
	
	return listValues;
}
 
Example 16
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short SECTokenGenerate(
Memory ServerName,
Memory OrgName,
Memory ConfigName,
Memory UserName,
NotesTimeDateStruct Creation,
NotesTimeDateStruct Expiration,
IntByReference retmhToken,
int dwReserved,
Pointer vpReserved);
 
Example 17
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
@UndocumentedAPI
public short NSFDbGetTcpHostName(
        int hDB,                                                        /* Database Handle           */ 
        Memory pszHostName,                                        /* Return TCP Host Name      */ 
        short wMaxHostNameLen,                                /* Size of Host Name Buffer  */ 
        Memory pszDomainName,                                        /* Return TCP Domain Name    */ 
        short wMaxDomainNameLen,                                /* Size of Domain Buffer     */ 
        Memory pszFullName,                                        /* Return Full TCP Name      */ 
        short wMaxFullNameLen);
 
Example 18
Source Project: domino-jna   Source File: ReadOnlyMemory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Memory align(int byteBoundary) {
	if (m_sealed)
		throw new UnsupportedOperationException();

	return super.align(byteBoundary);
}
 
Example 19
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public void MimeGetTypeInfoFromExt(
Memory pszExt,
Memory pszTypeBuf,
short wTypeBufLen,
Memory pszSubtypeBuf,
short wSubtypeBufLen,
Memory pszDescrBuf,
short wDescrBufLen);
 
Example 20
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short CalNoticeActionUNID(
int hDB,
NotesUniversalNoteIdStruct unid,
int dwAction,
Memory pszComments,
NotesCalendarActionDataStruct pExtActionInfo,
int dwFlags,
Pointer pCtx);
 
Example 21
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short CalGetUIDfromUNID(
int hDB,
NotesUniversalNoteIdStruct unid,
Memory pszUID,
short wLen,
Pointer pReserved,
int dwFlags,
Pointer pCtx);
 
Example 22
Source Project: domino-jna   Source File: NotesSearchKeyEncoder.java    License: 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 23
Source Project: domino-jna   Source File: INotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFDbCreateAndCopyExtended(
Memory srcDb,
Memory dstDb,
short NoteClass,
short limit,
int flags,
long hNames,
LongByReference hNewDb);
 
Example 24
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFNoteAttachFile(
int note_handle,
Memory item_name,
short item_name_length,
Memory file_name,
Memory orig_path_name,
short encoding_type);
 
Example 25
Source Project: domino-jna   Source File: NotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public native short MIMEGetText(
int hNote,
Memory pchItemName,
short wItemNameLen,
boolean bNotesEOL,
Memory pchBuf,
int dwMaxBufLen,
IntByReference pdwBufLen);
 
Example 26
Source Project: domino-jna   Source File: NotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public native short NSFItemInfo(
long note_handle,
Memory item_name,
short  name_len,
NotesBlockIdStruct retbhItem,
ShortByReference retDataType,
NotesBlockIdStruct retbhValue,
IntByReference retValueLength);
 
Example 27
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short NSFDbNoteLock(
int hDB,
int NoteID,
int Flags,
Memory pLockers,
IntByReference rethLockers,
IntByReference retLength);
 
Example 28
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short ACLUpdateEntry(
int hACL,
Memory name,
short updateFlags,
Memory newName,
short newAccessLevel,
Memory newPrivileges,
short newAccessFlags);
 
Example 29
Source Project: java-erasure   Source File: CodecUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts a java byte[][] array to JNA Pointer[] array.
 */
public static Pointer[] toPointerArray(byte[][] array) {
  Pointer[] ptrArray = new Pointer[array.length];
  for (int i = 0; i < array.length; ++i) {
    ptrArray[i] = new Memory(array[i].length);
    ptrArray[i].write(0, array[i], 0, array[i].length);
  }
  return ptrArray;
}
 
Example 30
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short ListAddEntry(
int hList,
int fPrefixDataType,
ShortByReference pListSize,
short EntryNumber,
Memory Text,
short TextSize);