Java Code Examples for com.sun.jna.Pointer#getIntArray()

The following examples show how to use com.sun.jna.Pointer#getIntArray() . 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: OSXNotifier.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(Pointer streamRef, Pointer clientCallBackInfo, NativeLong numEvents, Pointer eventPaths, Pointer eventFlags, Pointer eventIds) {
    final long st = System.currentTimeMillis();
    final int length = numEvents.intValue();
    final Pointer[] pointers = eventPaths.getPointerArray(0, length);
    int flags[];
    if (eventFlags == null) {
        flags = new int[length];
        LOG.log(DEBUG_LOG_LEVEL, "FSEventStreamCallback eventFlags == null, expected int[] of size {0}", length); //NOI18N
    } else {
        flags = eventFlags.getIntArray(0, length);
    }
    for (int i=0; i<length; i++) {
        final Pointer p = pointers[i];
        int flag = flags[i];
        final String path = p.getString(0);

        if ((flag & kFSEventStreamEventFlagMustScanSubDirs) ==  kFSEventStreamEventFlagMustScanSubDirs ||
            (flag & kFSEventStreamEventFlagMount) == kFSEventStreamEventFlagMount ||
            (flag & kFSEventStreamEventFlagUnmount) == kFSEventStreamEventFlagUnmount) {
            events.add(ALL_CHANGE);
        } else {
            events.add(path);
        }
        LOG.log(DEBUG_LOG_LEVEL, "Event on {0}", new Object[]{path});
    }
    LOG.log(PERF_LOG_LEVEL, "Callback time: {0}", (System.currentTimeMillis() - st));
}
 
Example 2
Source File: Nc4Iosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Array decodeVlen(DataType dt, int pos, ByteBuffer bbuff) throws IOException {
  Array array;
  int n = (int) bbuff.getLong(pos); // Note that this does not increment the buffer position
  long addr = getNativeAddr(pos + com.sun.jna.Native.POINTER_SIZE, bbuff);
  Pointer p = new Pointer(addr);
  Object data;
  switch (dt) {
    case BOOLEAN: /* byte[] */
    case ENUM1:
    case BYTE:
      data = p.getByteArray(0, n);
      break;
    case ENUM2:
    case SHORT: /* short[] */
      data = p.getShortArray(0, n);
      break;
    case ENUM4:
    case INT: /* int[] */
      data = p.getIntArray(0, n);
      break;
    case LONG: /* long[] */
      data = p.getLongArray(0, n);
      break;
    case FLOAT: /* float[] */
      data = p.getFloatArray(0, n);
      break;
    case DOUBLE: /* double[] */
      data = p.getDoubleArray(0, n);
      break;
    case CHAR: /* char[] */
      data = p.getCharArray(0, n);
      break;
    case STRING: /* String[] */
      // For now we need to use p.getString()
      // because p.getStringArray(int,int) does not exist
      // in jna version 3.0.9, but does exist in
      // verssion 4.0 and possibly some intermediate versions
      String[] stringdata = new String[n];
      for (int i = 0; i < n; i++)
        stringdata[i] = p.getString(i * 8);
      data = stringdata;
      break;
    case OPAQUE:
    case STRUCTURE:
    default:
      throw new IllegalStateException();
  }
  array = Array.factory(dt, new int[] {n}, data);
  return array;
}
 
Example 3
Source File: ItemDecoder.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
public static NotesTimeDate decodeTimeDateAsNotesTimeDate(final Pointer ptr, int valueLength) {
	int[] innards = ptr.getIntArray(0, 2);
	return new NotesTimeDate(innards);
}
 
Example 4
Source File: ItemDecoder.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
public static Calendar decodeTimeDate(final Pointer ptr, int valueLength) {
	int[] innards = ptr.getIntArray(0, 2);
	Calendar calDate = NotesDateTimeUtils.innardsToCalendar(innards);
	return calDate;
}
 
Example 5
Source File: ItemDecoder.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
public static List<Object> decodeTimeDateListAsNotesTimeDate(Pointer ptr) {
	NotesRangeStruct range = NotesRangeStruct.newInstance(ptr);
	range.read();
	
	//read number of list and range entries in range
	int listEntriesAsInt = range.ListEntries & 0xffff;
	int rangeEntriesAsInt = range.RangeEntries & 0xffff;
	
	//skip range header
	Pointer ptrAfterRange = ptr.share(NotesConstants.rangeSize);
	
	List<Object> calendarValues = new ArrayList<Object>(listEntriesAsInt + rangeEntriesAsInt);
	
	for (int t=0; t<listEntriesAsInt; t++) {
		Pointer ptrListEntry = ptrAfterRange.share(t * NotesConstants.timeDateSize);
		int[] innards = ptrListEntry.getIntArray(0, 2);
		calendarValues.add(new NotesTimeDate(innards));
	}
	
	//move position to the range data
	Pointer ptrAfterListEntries = ptrAfterRange.share(listEntriesAsInt * NotesConstants.timeDateSize);
	
	for (int t=0; t<rangeEntriesAsInt; t++) {
		Pointer ptrRangeEntry = ptrAfterListEntries.share(t * NotesConstants.timeDatePairSize);
		NotesTimeDatePairStruct timeDatePair = NotesTimeDatePairStruct.newInstance(ptrRangeEntry);
		timeDatePair.read();
		
		NotesTimeDateStruct lowerTimeDateStruct = timeDatePair.Lower;
		NotesTimeDateStruct upperTimeDateStruct = timeDatePair.Upper;
		
		int[] lowerTimeDateInnards = lowerTimeDateStruct.Innards;
		int[] upperTimeDateInnards = upperTimeDateStruct.Innards;
		
		NotesTimeDate lowerTimeDate = new NotesTimeDate(lowerTimeDateInnards);
		NotesTimeDate upperTimeDate = new NotesTimeDate(upperTimeDateInnards);
		
		calendarValues.add(new NotesDateRange(lowerTimeDate, upperTimeDate));
	}
	
	return calendarValues;

}
 
Example 6
Source File: ItemDecoder.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
public static List<Object> decodeTimeDateList(Pointer ptr) {
	NotesRangeStruct range = NotesRangeStruct.newInstance(ptr);
	range.read();
	
	//read number of list and range entries in range
	int listEntriesAsInt = range.ListEntries & 0xffff;
	int rangeEntriesAsInt = range.RangeEntries & 0xffff;
	
	//skip range header
	Pointer ptrAfterRange = ptr.share(NotesConstants.rangeSize);
	
	List<Object> calendarValues = new ArrayList<Object>(listEntriesAsInt + rangeEntriesAsInt);
	
	for (int t=0; t<listEntriesAsInt; t++) {
		Pointer ptrListEntry = ptrAfterRange.share(t * NotesConstants.timeDateSize);
		int[] innards = ptrListEntry.getIntArray(0, 2);
		Calendar calDate = NotesDateTimeUtils.innardsToCalendar(innards);
		if (calDate!=null) {
			calendarValues.add(calDate);
		}
		else {
			//invalid TimeDate detected; we produce a "null" value to be able to detect this error
			Calendar nullCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
			nullCal.set(Calendar.YEAR, 1);
			nullCal.set(Calendar.MONTH, 1);
			nullCal.set(Calendar.DAY_OF_MONTH, 1);
			nullCal.set(Calendar.HOUR, 0);
			nullCal.set(Calendar.MINUTE, 0);
			nullCal.set(Calendar.SECOND, 0);
			nullCal.set(Calendar.MILLISECOND, 0);
			calendarValues.add(nullCal);
		}
	}
	
	//move position to the range data
	Pointer ptrAfterListEntries = ptrAfterRange.share(listEntriesAsInt * NotesConstants.timeDateSize);
	
	for (int t=0; t<rangeEntriesAsInt; t++) {
		Pointer ptrRangeEntry = ptrAfterListEntries.share(t * NotesConstants.timeDatePairSize);
		NotesTimeDatePairStruct timeDatePair = NotesTimeDatePairStruct.newInstance(ptrRangeEntry);
		timeDatePair.read();
		
		NotesTimeDateStruct lowerTimeDate = timeDatePair.Lower;
		NotesTimeDateStruct upperTimeDate = timeDatePair.Upper;
		
		int[] lowerTimeDateInnards = lowerTimeDate.Innards;
		int[] upperTimeDateInnards = upperTimeDate.Innards;
		
		Calendar lowerCalDate = NotesDateTimeUtils.innardsToCalendar(lowerTimeDateInnards);
		if (lowerCalDate==null) {
			//invalid TimeDate detected; we produce a "null" value to be able to detect this error
			lowerCalDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
			lowerCalDate.set(Calendar.YEAR, 1);
			lowerCalDate.set(Calendar.MONTH, 1);
			lowerCalDate.set(Calendar.DAY_OF_MONTH, 1);
			lowerCalDate.set(Calendar.HOUR, 0);
			lowerCalDate.set(Calendar.MINUTE, 0);
			lowerCalDate.set(Calendar.SECOND, 0);
			lowerCalDate.set(Calendar.MILLISECOND, 0);
		}
		Calendar upperCalDate = NotesDateTimeUtils.innardsToCalendar(upperTimeDateInnards);
		if (upperCalDate==null) {
			//invalid TimeDate detected; we produce a "null" value to be able to detect this error
			upperCalDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
			upperCalDate.set(Calendar.YEAR, 0);
			upperCalDate.set(Calendar.MONTH, 0);
			upperCalDate.set(Calendar.DAY_OF_MONTH, 0);
			upperCalDate.set(Calendar.HOUR, 0);
			upperCalDate.set(Calendar.MINUTE, 0);
			upperCalDate.set(Calendar.SECOND, 0);
			upperCalDate.set(Calendar.MILLISECOND, 0);
		}
		
		calendarValues.add(new Calendar[] {lowerCalDate, upperCalDate});
	}
	
	return calendarValues;
}
 
Example 7
Source File: CauchyReedSolomonCodec.java    From java-erasure with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a Cauchy matrix over GF(2^w).
 *
 * @param k The column number
 * @param m The row number
 * @param w The word size, used to define the finite field
 * @return The generated Cauchy matrix
 */
int[] createCauchyMatrix(int k, int m , int w) {
  Pointer matrix = JerasureLibrary.INSTANCE
      .cauchy_original_coding_matrix(k, m, w);
  return matrix.getIntArray(0, k * m);
}
 
Example 8
Source File: CauchyReedSolomonCodec.java    From java-erasure with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a optimized Cauchy matrix over GF(2^w).
 *
 * @param k The column number
 * @param m The row number
 * @param w The word size, used to define the finite field
 * @return The generated Cauchy matrix
 */
int[] createGoodCauchyMatrix(int k, int m , int w) {
  Pointer matrix = JerasureLibrary.INSTANCE
      .cauchy_good_general_coding_matrix(k, m, w);
  return matrix.getIntArray(0, k * m);
}
 
Example 9
Source File: CauchyReedSolomonCodec.java    From java-erasure with Apache License 2.0 2 votes vote down vote up
/**
 * Converts the Cauchy matrix to a bit matrix over GF(2^w).
 *
 * @param k The column number
 * @param m The row number
 * @param w The word size, used to define the finite field
 * @param matrix The cauchy matrix
 * @return The converted bit matrix
 */
int[] convertToBitMatrix(int k, int m, int w, int[] matrix) {
  Pointer bit_matrix = JerasureLibrary.INSTANCE.jerasure_matrix_to_bitmatrix(
      k, m, w, matrix);
  return bit_matrix.getIntArray(0, k * w * m * w);
}
 
Example 10
Source File: ReedSolomonCodec.java    From java-erasure with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a Vandermonde matrix of m x k over GF(2^w).
 *
 * @param k The column number
 * @param m The row number
 * @param w The word size, used to define the finite field
 * @return The generated Vandermonde matrix
 */
int[] createVandermondeMatrix(int k, int m, int w) {
  Pointer matrix = JerasureLibrary.INSTANCE
      .reed_sol_vandermonde_coding_matrix(k, m, w);
  return matrix.getIntArray(0, k * m);
}