Java Code Examples for com.sun.jna.Memory#getShort()
The following examples show how to use
com.sun.jna.Memory#getShort() .
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: PropertyGetLogicDefault.java From canon-sdk-java with MIT License | 4 votes |
@Override @SuppressWarnings("unchecked") public <T> T getPropertyData(final EdsBaseRef ref, final EdsPropertyID property, final long inParam) { final PropertyInfo propertyInfo = CanonFactory.propertyLogic().getPropertyTypeAndSize(ref, property, inParam); final EdsDataType propertyType = propertyInfo.getDataType(); final long propertySize = propertyInfo.getSize(); final Memory propertyData = getMemoryForHoldingData(propertySize > 0 ? propertySize : 1); final EdsdkError error = getPropertyData(ref, property, inParam, propertySize, propertyData); if (!EdsdkError.EDS_ERR_OK.equals(error)) { log.error("Failed to get property data {}, inParam: {}, propertyType:{}, propertySize: {}", property, inParam, propertyType, propertySize); throw error.getException(); } switch (propertyType) { case kEdsDataType_Unknown: throw new IllegalStateException("Unknown data type returned by camera to get property data"); case kEdsDataType_Bool: // TODO not tested final Boolean b = propertyData.getByte(0) != 0; log.warn("to test: {}, {}, {}", b, propertyData, propertyData.dump()); return (T) b; case kEdsDataType_String: return (T) propertyData.getString(0); case kEdsDataType_Int8: case kEdsDataType_UInt8: return (T) (Byte) propertyData.getByte(0); case kEdsDataType_Int16: case kEdsDataType_UInt16: return (T) (Short) propertyData.getShort(0); case kEdsDataType_Int32: case kEdsDataType_UInt32: return (T) (Long) propertyData.getNativeLong(0).longValue(); case kEdsDataType_Int64: case kEdsDataType_UInt64: return (T) (Long) propertyData.getLong(0); case kEdsDataType_Float: return (T) (Float) propertyData.getFloat(0); case kEdsDataType_Double: return (T) (Double) propertyData.getDouble(0); case kEdsDataType_ByteBlock: // TODO not tested // not tested and documentation gives this data type as many types : // EdsInt8[] // EdsUInt32[] return (T) propertyData.getIntArray(0, (int) (propertySize / 4)); case kEdsDataType_Rational: return (T) new EdsRational(propertyData); case kEdsDataType_Point: return (T) new EdsPoint(propertyData); case kEdsDataType_Rect: return (T) new EdsRect(propertyData); case kEdsDataType_Time: return (T) new EdsTime(propertyData); case kEdsDataType_Bool_Array: // TODO not tested log.warn("to test: {}, {}", propertyData, propertyData.dump()); throw new NotImplementedException("to test"); case kEdsDataType_Int8_Array: case kEdsDataType_UInt8_Array: // TODO maybe use intArray return (T) propertyData.getByteArray(0, (int) propertySize); case kEdsDataType_Int16_Array: case kEdsDataType_UInt16_Array: // TODO maybe use intArray return (T) propertyData.getShortArray(0, (int) (propertySize / 2)); case kEdsDataType_Int32_Array: case kEdsDataType_UInt32_Array: // TODO maybe use longArray return (T) propertyData.getIntArray(0, (int) (propertySize / 4)); case kEdsDataType_Rational_Array: // TODO not tested log.warn("to test: {}, {}", propertyData, propertyData.dump()); throw new NotImplementedException("to test"); case kEdsDataType_FocusInfo: return (T) new EdsFocusInfo(propertyData); case kEdsDataType_PictureStyleDesc: return (T) new EdsPictureStyleDesc(propertyData); default: log.error("Unknown property type: {}, {}", propertyType, propertyType.value()); throw new IllegalStateException("Unknown property type: " + propertyType + ", " + propertyType.value()); } }
Example 2
Source File: RemoveFileHotspotConversion.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Traverses the CD record stream searching for records BEGIN followed by HOTSPOTBEGIN with the unique * filename we are searching for. * * @param nav navigator * @param startPos start position for the search or null to start at the beginning of the stream * @param copyToTarget if not null, we copy all records we find until the right BEGIN record to this target * @return position of the BEGIN record or null if not found */ private RichTextNavPosition scanForBeginOfHotspot(IRichTextNavigator nav, RichTextNavPosition startPos, ICompoundText copyToTarget) { if (startPos!=null) { nav.restoreCurrentRecordPosition(startPos); } else { if (!nav.gotoFirst()) { return null; } } do { if (CDRecordType.BEGIN.getConstant() == nav.getCurrentRecordTypeAsShort()) { // typedef struct { // BSIG Header; /* Signature and length of this record */ // WORD Version; // WORD Signature; /* Signature of record begin is for */ // } CDBEGINRECORD; Memory beginDataBuf = nav.getCurrentRecordData(); int version = beginDataBuf.getShort(0); int signature = beginDataBuf.share(2).getShort(0); if (signature == NotesConstants.SIG_CD_V4HOTSPOTBEGIN) { RichTextNavPosition savedPos = nav.getCurrentRecordPosition(); if (nav.gotoNext()) { //check what is next if (CDRecordType.HOTSPOTBEGIN.getConstant() == nav.getCurrentRecordTypeAsShort()) { // typedef struct { // WSIG Header; /* Signature and length of this record */ // WORD Type; // DWORD Flags; // WORD DataLength; // Data follows... /* if HOTSPOTREC_RUNFLAG_SIGNED, WORD SigLen then SigData follows. */ // } CDHOTSPOTBEGIN; Memory hotspotRecordDataBuf = nav.getCurrentRecordData(); short type = hotspotRecordDataBuf.getShort(0); if (type == NotesConstants.HOTSPOTREC_TYPE_FILE) { int flags = hotspotRecordDataBuf.share(2).getInt(0); int dataLength = (int) (hotspotRecordDataBuf.share(6).getShort(0) & 0xffff); String uniqueFileName = NotesStringUtils.fromLMBCS(hotspotRecordDataBuf.share(8), -1); if (uniqueFileName.equalsIgnoreCase(m_attachmentFileName)) { return savedPos; } } } } nav.restoreCurrentRecordPosition(savedPos); } if (copyToTarget!=null) { nav.copyCurrentRecordTo(copyToTarget); } } else { if (copyToTarget!=null) { nav.copyCurrentRecordTo(copyToTarget); } } } while (nav.gotoNext()); return null; }
Example 3
Source File: RichTextUtils.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Traverses the richtext CD records and collects the filenames of all * attachment icons. Restores the * current {@link RichTextNavPosition} in the richtext item if not * null. * * @param rtNav richtext navigator * @return attachment names in order of appearance */ public static LinkedHashSet<String> collectAttachmentNames(IRichTextNavigator rtNav) { LinkedHashSet<String> attNames = new LinkedHashSet<>(); if (rtNav==null) { return attNames; } RichTextNavPosition oldPos = rtNav.getCurrentRecordPosition(); if (rtNav.gotoFirst()) { do { if (CDRecordType.BEGIN.getConstant() == rtNav.getCurrentRecordTypeAsShort()) { // typedef struct { // BSIG Header; /* Signature and length of this record */ // WORD Version; // WORD Signature; /* Signature of record begin is for */ // } CDBEGINRECORD; Memory beginDataBuf = rtNav.getCurrentRecordData(); int version = beginDataBuf.getShort(0); int signature = beginDataBuf.share(2).getShort(0); if (signature == NotesConstants.SIG_CD_V4HOTSPOTBEGIN) { RichTextNavPosition savedPos = rtNav.getCurrentRecordPosition(); if (rtNav.gotoNext()) { //check what is next if (CDRecordType.HOTSPOTBEGIN.getConstant() == rtNav.getCurrentRecordTypeAsShort()) { // typedef struct { // WSIG Header; /* Signature and length of this record */ // WORD Type; // DWORD Flags; // WORD DataLength; // Data follows... /* if HOTSPOTREC_RUNFLAG_SIGNED, WORD SigLen then SigData follows. */ // } CDHOTSPOTBEGIN; Memory hotspotRecordDataBuf = rtNav.getCurrentRecordData(); short type = hotspotRecordDataBuf.getShort(0); if (type == NotesConstants.HOTSPOTREC_TYPE_FILE) { String uniqueFileName = NotesStringUtils.fromLMBCS(hotspotRecordDataBuf.share(8), -1); attNames.add(uniqueFileName); } } } rtNav.restoreCurrentRecordPosition(savedPos); } } } while (rtNav.gotoNext()); } if (oldPos!=null) { rtNav.restoreCurrentRecordPosition(oldPos); } return attNames; }
Example 4
Source File: CDFileRichTextNavigator.java From domino-jna with Apache License 2.0 | 4 votes |
/** * Reads the CD record information at the current file position * * @throws IOException */ private CDRecordMemory readCurrentCDRecord() throws IOException { m_fileChannel.position(m_position); Memory signatureMem = new Memory(2); ByteBuffer signatureBuf = signatureMem.getByteBuffer(0, signatureMem.size()); m_fileChannel.read(signatureBuf); short typeAsShort = signatureMem.getShort(0); int dwLength; /* structures used to define and read the signatures 0 1 +---------+---------+ | Sig | Length | Byte signature +---------+---------+ 0 1 2 3 +---------+---------+---------+---------+ | Sig | ff | Length | Word signature +---------+---------+---------+---------+ 0 1 2 3 4 5 +---------+---------+---------+---------+---------+---------+ | Sig | 00 | Length | DWord signature +---------+---------+---------+---------+---------+---------+ */ short highOrderByte = (short) (typeAsShort & 0xFF00); int fixedSize; switch (highOrderByte) { case NotesConstants.LONGRECORDLENGTH: /* LSIG */ Memory intLengthMem = new Memory(4); ByteBuffer intLengthBuf = intLengthMem.getByteBuffer(0, intLengthMem.size()); m_fileChannel.read(intLengthBuf); dwLength = intLengthMem.getInt(0); fixedSize = 6; //sizeof(LSIG); break; case NotesConstants.WORDRECORDLENGTH: /* WSIG */ Memory shortLengthMem = new Memory(2); ByteBuffer shortLengthBuf = shortLengthMem.getByteBuffer(0, shortLengthMem.size()); m_fileChannel.read(shortLengthBuf); dwLength = (int) (shortLengthMem.getShort(0) & 0xffff); fixedSize = 4; //sizeof(WSIG); break; default: /* BSIG */ dwLength = (int) ((typeAsShort >> 8) & 0x00ff); typeAsShort &= 0x00FF; /* Length not part of signature */ fixedSize = 2; //sizeof(BSIG); } //file channel position points to the start of data, so reset it to the CD record start m_fileChannel.position(m_position); int cdRecordTotalLength = dwLength; ReadOnlyMemory cdRecordMem = new ReadOnlyMemory(cdRecordTotalLength); int bytesRead = m_fileChannel.read(cdRecordMem.getByteBuffer(0, cdRecordMem.size())); if (bytesRead != cdRecordTotalLength) { throw new IllegalStateException("Bytes read from CD record file for CD record at index "+m_currentCDRecordIndex+" is expected to be "+cdRecordTotalLength+" but we only could read "+bytesRead+" bytes"); } cdRecordMem.seal(); CDRecordMemory record = new CDRecordMemory(cdRecordMem, typeAsShort, dwLength-fixedSize, dwLength); //remember the length of the CD records m_cdRecordSizeAtIndex.put(m_currentCDRecordIndex, record.getCDRecordLength()); m_cdRecordIndexAtFilePos.put(m_position, m_currentCDRecordIndex); return record; }
Example 5
Source File: JnaUnixMediatorImpl.java From consulo with Apache License 2.0 | 4 votes |
private int getModeFlags(Memory buffer) { return SystemInfo.isLinux ? buffer.getInt(myOffsets[OFF_MODE]) : buffer.getShort(myOffsets[OFF_MODE]); }