public static <T> List<T> fromNullTerminatedArray(XfsVersion xfsVersion, Pointer p, Class<T> type) { List<T> result = new ArrayList<>(); for (Pointer each : new ZList(p)) { result.add(create(xfsVersion, each, type)); } return Collections.unmodifiableList(result); } }
public <T extends Type> ZList(List<T> types) { for (int i = 0; i < types.size(); i++) { pointers.add(new Pointer()); } allocate(); int offset = 0; for (int i = 0; i < types.size(); i++) { Pointer p = pointers.get(i); p.assignBuffer(getBuffer().subBuffer(offset, p.getSize())); p.pointTo(types.get(i)); offset += p.getSize(); } }
public ZList(Pointer pointer) { int offset = 0; Buffer buffer = null; while (true) { buffer = pointer.buffer(offset + pointer.getSize()); Pointer p = new Pointer(buffer.subBuffer(offset, pointer.getSize())); if (Pointer.NULL.equals(p)) { break; } pointers.add(p); offset += p.getSize(); } assignBuffer(buffer); }
@Override protected ReadImageCompleteEvent createCompleteEvent(Pointer results) { final String method = "createCompleteEvent(Pointer)"; List<Image3> images = new ArrayList<Image3>(); ZList list = new ZList(results); for (Pointer p : list) { Image3 image = PtrFactory.INSTANCE.create(ptrService.getXfsVersion(), p, Image3.class); if (LOG.isDebugEnabled()) { LOG.debug(method, "image=" + image); } images.add(image); } return new ReadImageCompleteEvent(images); } }
@Override public Collection<CurrencyExp3> call() throws XfsException { List<CurrencyExp3> result; XfsInfoCommand<CdmInfoCommand> infoCommand = new XfsInfoCommand<CdmInfoCommand>(service, CdmInfoCommand.CURRENCY_EXP); WFSResult wfsResult = null; try { wfsResult = infoCommand.call(); result = new ArrayList<>(); ZList lppCurrencyExp = new ZList(wfsResult.getResults()); for (Pointer p : lppCurrencyExp) { result.add(ReflectiveFactory.create(service.getXfsVersion(), p, CurrencyExp3.class)); } } finally { if (wfsResult != null) { XfsServiceManager.getInstance().free(wfsResult); } } return Collections.unmodifiableList(result); } }
@Test public final void test() { ZList currencyExp3 = new ZList(buildCurrencyExp3().getPointer()); for (Pointer each : currencyExp3) { CurrencyExp3 expected = new CurrencyExp3(each); CurrencyExp3 actual = new CurrencyExp3(expected); System.out.println(actual); assertEquals(expected, actual); } }
@Test public final void test() { ZList lppMixTypes = new ZList(buildMixTypes3().getPointer()); for (Pointer each : lppMixTypes) { MixType3 expected = new MixType3(each); MixType3 actual = new MixType3(expected); System.out.println(actual); assertEquals(expected, actual); } }
@Override public void fireOperationCompleteEvent(final WFSResult wfsResult) { final String method = "fireOperationCompleteEvent(WFSResult)"; try { if (LOG.isDebugEnabled()) { LOG.debug(method, "wfsResult=" + wfsResult); } XfsException.throwFor(wfsResult.getResult()); final List<CardData3> cardDataList = new ArrayList<CardData3>(); final ZList zList = new ZList(wfsResult.getResults()); for (final Pointer pCardData : zList) { final CardData3 cardData = IdcFactory.create(idcService.getXfsVersion(), pCardData, CardData3.class); if (LOG.isDebugEnabled()) { LOG.debug(method, "cardData=" + cardData); } cardDataList.add(cardData); } notifyCardRead(cardDataList); notifyCommandSuccessful(); } catch (XfsCancelledException e) { notifyCommandCancelled(); } catch (XfsException e) { notifyCommandFailed(e); } finally { serviceManager.free(wfsResult); } } }
@Test public void keyDetail() throws Exception { for (final PINService pinService : serviceManager.getServices(PINService.class)) { final XfsCommand xfsCommand = new XfsInfoCommand<PINInfoCommand>(pinService, PINInfoCommand.KEY_DETAIL); WFSResult wfsResult = null; try { wfsResult = xfsCommand.call(); ZList pKeyDetails = new ZList(wfsResult.getResults()); for (Pointer pKeyDetail : pKeyDetails) { WFSPINKEYDETAIL keyDetail = new WFSPINKEYDETAIL(pinService.getXfsVersion(), pKeyDetail); System.out.println(keyDetail); } } finally { if (wfsResult != null) { serviceManager.free(wfsResult); } } } }