• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java State类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.smartcardio.CardTerminals.State的典型用法代码示例。如果您正苦于以下问题:Java State类的具体用法?Java State怎么用?Java State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



State类属于javax.smartcardio.CardTerminals包,在下文中一共展示了State类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: byATR

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
/**
 * Return a list of CardTerminal-s that contain a card with one of the specified ATR-s.
 * The reader might be unusable (in use in exclusive mode).
 *
 * @param atrs Collection of ATR-s to match
 * @return list of CardTerminal-s
 * @throws NoSuchAlgorithmException if PC/SC is not present/running
 * @throws CardException            if PC/SC error happens
 */
public static List<CardTerminal> byATR(Collection<ATR> atrs) throws NoSuchAlgorithmException, CardException {
    TerminalFactory tf = TerminalFactory.getInstance("PC/SC", null, new jnasmartcardio.Smartcardio());
    CardTerminals ts = tf.terminals();
    List<CardTerminal> tl = ts.list(State.ALL);
    ArrayList<CardTerminal> result = new ArrayList<>();
    for (CardTerminal t : tl) {
        logger.trace("Checking {}", t.getName());
        if (t.isCardPresent()) {
            // TODO: only cards available, not exclusively used
            Card c = t.connect("DIRECT");
            ATR cardatr = c.getATR();
            c.disconnect(false);

            for (ATR atr : atrs) {
                if (cardatr.equals(atr)) {
                    logger.debug("{} matched for ATR {}", t.getName(), HexUtils.bin2hex(atr.getBytes()));
                    result.add(t);
                }
            }
        }
    }
    return result;
}
 
开发者ID:martinpaljak,项目名称:apdu4j,代码行数:33,代码来源:TerminalManager.java


示例2: getByATRBytes

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
public static CardTerminal getByATRBytes(Collection<byte[]> atrs) throws NoSuchAlgorithmException, CardException {
    TerminalFactory tf = TerminalFactory.getInstance("PC/SC", null, new jnasmartcardio.Smartcardio());
    CardTerminals ts = tf.terminals();
    List<CardTerminal> tl = ts.list(State.ALL);
    // If all are empty, wait for an entry.
    for (CardTerminal t : tl) {
        logger.trace("Checking {}", t.getName());
        if (t.isCardPresent()) {
            Card c = t.connect("DIRECT");
            byte[] cardatr = c.getATR().getBytes();
            c.disconnect(false);

            for (byte[] atr : atrs) {
                if (Arrays.equals(cardatr, atr)) {
                    logger.debug("{} matched for ATR {}", t.getName(), HexUtils.bin2hex(atr));
                    return t;
                }
            }
        }
    }
    throw new CardNotPresentException("No card with requested ATR present");
}
 
开发者ID:martinpaljak,项目名称:apdu4j,代码行数:23,代码来源:TerminalManager.java


示例3: run

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
public void run() throws Exception {
	Security.insertProviderAt(new SmartcardioProvider(), 1);
	//
	TerminalFactory factory = TerminalFactory.getDefault();
	CardTerminals terminals = factory.terminals();
	while (System.in.available() == 0) {
		List<CardTerminal> list = terminals.list(State.CARD_INSERTION);
		if (list.isEmpty()) {
			System.out.println("no terminals");
		}
		for (CardTerminal cardTerminal : list) {
			try {
				connect(cardTerminal);
			} catch (Exception e) {
				System.out.println("error connecting " + e);
			}
		}
		System.out.println("wait for change");
		if (terminals.waitForChange(1000)) {
			System.out.println("change detected...");
		} else {
			System.out.println("timeout");
		}
	}
}
 
开发者ID:intarsys,项目名称:smartcard-io,代码行数:26,代码来源:Connect.java


示例4: main

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	TerminalFactory context;
	CardTerminals terminals;
	if (true) {
		Security.addProvider(new Smartcardio());
		context = TerminalFactory.getInstance("PC/SC", null, Smartcardio.PROVIDER_NAME);
		terminals = context.terminals();
	} else {
		TerminalFactory terminalFactory = TerminalFactory.getDefault();
		terminals = terminalFactory.terminals();
	}
	List<CardTerminal> present = terminals.list(State.CARD_PRESENT);
	List<CardTerminal> absent = terminals.list(State.CARD_ABSENT);
	System.out.format("Initial: cards are present in %s; cards are absent from %s%n", terminalNames(present), terminalNames(absent));
	while (true) {
		terminals.waitForChange();
		List<CardTerminal> inserted = terminals.list(State.CARD_INSERTION);
		List<CardTerminal> removed = terminals.list(State.CARD_REMOVAL);
		System.out.format("Card inserted in %s; cards removed from %s%n", terminalNames(inserted), terminalNames(removed));
	}
}
 
开发者ID:jnasmartcardio,项目名称:jnasmartcardio,代码行数:22,代码来源:WaitForChange.java


示例5: isCardPresent

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
private boolean isCardPresent()
{
	try
	{
		return !cardTerminals.terminals().list(State.CARD_PRESENT).isEmpty();
	}
	catch (javax.smartcardio.CardException e)
	{
		logger.warn("Error while accessing card terminals", e);
		return false;
	}
}
 
开发者ID:patrick-werner,项目名称:EGKfeuer,代码行数:13,代码来源:CardReaderServiceImpl.java


示例6: setUp

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
@Before
public void setUp() throws Exception
{
	terminallist = new ArrayList<CardTerminal>();
	terminallistCardPresent = new ArrayList<CardTerminal>();

	CardTerminalsService cardTerminalService = EasyMock.createMock(CardTerminalsService.class);
	CardTerminals cardTerminals = EasyMock.createMock(CardTerminals.class);
	EasyMock.expect(cardTerminalService.terminals()).andReturn(cardTerminals).anyTimes();
	EasyMock.expect(cardTerminals.list()).andReturn(terminallist).anyTimes();
	EasyMock.expect(cardTerminals.list(State.CARD_PRESENT)).andReturn(terminallistCardPresent)
			.anyTimes();
	EasyMock.replay(cardTerminals, cardTerminalService);

	cardReaderService = new CardReaderServiceImpl(new ToPatientConverter()
	{
		@Override
		public EgkPatient toPatient(String pdContent, String vdContent)
		{
			return new EgkPatient("title", "givenName", "surname", "vorsatzwort", "namenszusatz", LocalDate.now(), Sex.FEMALE, "zip", "city",
					"streetname", "housenumber", "healthInsuranceProviderNumber", "healthInsuranceNumber", "versichertenID");
		}

		@Override
		public boolean isVdCompatible(String vdContent)
		{
			return true;
		}

		@Override
		public boolean isPdCompatible(String pdContent)
		{
			return true;
		}
	}, cardTerminalService);
}
 
开发者ID:patrick-werner,项目名称:EGKfeuer,代码行数:37,代码来源:CardReaderServiceTest.java


示例7: getTheReader

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
/**
 * Returns a card reader that has a card in it.
 * Asks for card insertion, if the system only has a single reader.
 *
 * @return a CardTerminal containing a card
 * @throws CardException if no suitable reader is found.
 */
public static CardTerminal getTheReader(String spec) throws CardException {
    try {
        String msg = "This application expects one and only one card reader (with an inserted card)";
        TerminalFactory tf = getTerminalFactory(spec);
        CardTerminals tl = tf.terminals();
        List<CardTerminal> list = tl.list(State.CARD_PRESENT);
        if (list.size() > 1) {
            throw new CardException(msg);
        } else if (list.size() == 1) {
            return list.get(0);
        } else {
            List<CardTerminal> wl = tl.list(State.ALL);
            // FIXME: JNA-s CardTerminals.waitForChange() does not work
            if (wl.size() == 1) {
                CardTerminal t = wl.get(0);
                System.out.println("Waiting for a card insertion to " + t.getName());
                if (t.waitForCardPresent(0)) {
                    return t;
                } else {
                    throw new CardException("Could not find a reader with a card");
                }
            } else {
                throw new CardException(msg);
            }
        }
    } catch (NoSuchAlgorithmException e) {
        throw new CardException(e);
    }
}
 
开发者ID:martinpaljak,项目名称:apdu4j,代码行数:37,代码来源:TerminalManager.java


示例8: getByAID

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
public static CardTerminal getByAID(Collection<byte[]> aids) throws NoSuchAlgorithmException, CardException {
    TerminalFactory tf = TerminalFactory.getInstance("PC/SC", null, new jnasmartcardio.Smartcardio());
    CardTerminals ts = tf.terminals();
    List<CardTerminal> tl = ts.list(State.ALL);
    for (CardTerminal t : tl) {
        if (t.isCardPresent()) {
            Card c = null;
            try {
                c = t.connect("*");
                for (byte[] aid : aids) {
                    // Try to select the AID
                    CommandAPDU s = new CommandAPDU(0x00, 0xA4, 0x04, 0x00, aid, 256);
                    ResponseAPDU r = c.getBasicChannel().transmit(s);
                    if (r.getSW() == 0x9000) {
                        logger.debug("{} matched for AID {}", t.getName(), HexUtils.bin2hex(aid));
                        return t;
                    }
                }
            } catch (CardException e) {
                logger.trace("Could not connect or select AID", e);
                continue;
            } finally {
                if (c != null)
                    c.disconnect(false);
            }
        }
    }
    throw new CardNotPresentException("No card with requested AID present");
}
 
开发者ID:martinpaljak,项目名称:apdu4j,代码行数:30,代码来源:TerminalManager.java


示例9: getPluggedTerminalsWithSmartCards

import javax.smartcardio.CardTerminals.State; //导入依赖的package包/类
private static List<CardTerminal> getPluggedTerminalsWithSmartCards() throws CardException{
	return getSmartCardPluggedTerminals().list(State.CARD_PRESENT);
}
 
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:4,代码来源:SmartCardUtil.java



注:本文中的javax.smartcardio.CardTerminals.State类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SyncFactory类代码示例发布时间:2022-05-23
下一篇:
Java ByteArrayEncoder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap