Example usage for javax.smartcardio CardTerminals list

List of usage examples for javax.smartcardio CardTerminals list

Introduction

In this page you can find the example usage for javax.smartcardio CardTerminals list.

Prototype

public List<CardTerminal> list() throws CardException 

Source Link

Document

Returns an unmodifiable list of all available terminals.

Usage

From source file:de.willuhn.jameica.hbci.passports.pintan.Controller.java

/**
 * Liefert eine Auswahl verfuegbarer Kartenleser-Bezeichnungen.
 * @return eine Auswahl verfuegbaren Kartenleser-Bezeichnungen.
 * @throws RemoteException//from w  w  w  .ja va2  s .  c  o  m
 */
public SelectInput getCardReaders() throws RemoteException {
    if (this.cardReaders != null)
        return this.cardReaders;

    List<String> available = new ArrayList<String>();

    // Erste Zeile Leerer Eintrag.
    // Damit das Feld auch dann leer bleiben kann, wenn der User nur einen
    // Kartenleser hat. Der sollte dann nicht automatisch vorselektiert
    // werden, da dessen Bezeichnung sonst unnoetigerweise hart gespeichert wird
    available.add("");
    try {
        TerminalFactory terminalFactory = TerminalFactory.getDefault();
        CardTerminals terminals = terminalFactory.terminals();
        if (terminals != null) {
            List<CardTerminal> list = terminals.list();
            if (list != null && list.size() > 0) {
                for (CardTerminal t : list) {
                    String name = StringUtils.trimToNull(t.getName());
                    if (name != null)
                        available.add(name);
                }
            }
        }
    } catch (Throwable t) {
        Logger.info("unable to determine card reader list: " + t.getMessage());
        Logger.write(Level.DEBUG, "stacktrace for debugging purpose", t);
    }

    this.cardReaders = new SelectInput(available, this.getConfig().getCardReader());
    this.cardReaders.setEditable(true);
    this.cardReaders.setComment(i18n.tr("nur ntig, wenn mehrere Leser vorhanden"));
    this.cardReaders.setName(i18n.tr("Identifier des PC/SC-Kartenlesers"));
    return this.cardReaders;
}

From source file:test.be.fedict.eid.applet.PcscTest.java

@Test
public void testReadPhoto() throws Exception {
    TerminalFactory terminalFactory = TerminalFactory.getDefault();
    CardTerminals cardTerminals = terminalFactory.terminals();
    CardTerminal cardTerminal = cardTerminals.list().get(0);
    Card card = cardTerminal.connect("T=0");
    CardChannel cardChannel = card.getBasicChannel();
    // select file
    cardChannel.transmit(//from w w w  .  j a v  a2  s  .c  o  m
            new CommandAPDU(0x00, 0xA4, 0x08, 0x0C, new byte[] { 0x3F, 0x00, (byte) 0xDF, 0x01, 0x40, 0x35 }));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int offset = 0;
    ResponseAPDU responseApdu;
    do {
        // read binary
        responseApdu = cardChannel.transmit(new CommandAPDU(0x00, 0xB0, offset >> 8, offset & 0xFF, 0xff));
        baos.write(responseApdu.getData());
        offset += responseApdu.getData().length;
    } while (responseApdu.getData().length == 0xff);
    BufferedImage photo = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
    JOptionPane.showMessageDialog(null, new ImageIcon(photo));
}