Java Code Examples for javax.smartcardio.CardTerminal#waitForCardPresent()

The following examples show how to use javax.smartcardio.CardTerminal#waitForCardPresent() . 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: Utils.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static CardTerminal getTerminal(String[] args) throws Exception {
    setLibrary(args);

    TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
    System.out.println(factory);

    List<CardTerminal> terminals = factory.terminals().list();
    System.out.println("Terminals: " + terminals);
    if (terminals.isEmpty()) {
        throw new Exception("No card terminals available");
    }
    CardTerminal terminal = terminals.get(0);

    if (terminal.isCardPresent() == false) {
        System.out.println("*** Insert card");
        if (terminal.waitForCardPresent(20 * 1000) == false) {
            throw new Exception("no card available");
        }
    }
    return terminal;
}
 
Example 2
Source File: Utils.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static CardTerminal getTerminal(String[] args) throws Exception {
    setLibrary(args);

    TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
    System.out.println(factory);

    List<CardTerminal> terminals = factory.terminals().list();
    System.out.println("Terminals: " + terminals);
    if (terminals.isEmpty()) {
        throw new Exception("No card terminals available");
    }
    CardTerminal terminal = terminals.get(0);

    if (terminal.isCardPresent() == false) {
        System.out.println("*** Insert card");
        if (terminal.waitForCardPresent(20 * 1000) == false) {
            throw new Exception("no card available");
        }
    }
    return terminal;
}
 
Example 3
Source File: Utils.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static CardTerminal getTerminal(String[] args) throws Exception {
    setLibrary(args);

    TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
    System.out.println(factory);

    List<CardTerminal> terminals = factory.terminals().list();
    System.out.println("Terminals: " + terminals);
    if (terminals.isEmpty()) {
        throw new Exception("No card terminals available");
    }
    CardTerminal terminal = terminals.get(0);

    if (terminal.isCardPresent() == false) {
        System.out.println("*** Insert card");
        if (terminal.waitForCardPresent(20 * 1000) == false) {
            throw new Exception("no card available");
        }
    }
    return terminal;
}
 
Example 4
Source File: Utils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static CardTerminal getTerminal(String[] args) throws Exception {
    setLibrary(args);

    TerminalFactory factory = TerminalFactory.getInstance("PC/SC", null);
    System.out.println(factory);

    List<CardTerminal> terminals = factory.terminals().list();
    System.out.println("Terminals: " + terminals);
    if (terminals.isEmpty()) {
        throw new Exception("No card terminals available");
    }
    CardTerminal terminal = terminals.get(0);

    if (terminal.isCardPresent() == false) {
        System.out.println("*** Insert card");
        if (terminal.waitForCardPresent(20 * 1000) == false) {
            throw new Exception("no card available");
        }
    }
    return terminal;
}
 
Example 5
Source File: Utils.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 6
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 7
Source File: Utils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 8
Source File: Utils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 9
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 10
Source File: Utils.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 11
Source File: Utils.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 12
Source File: TouchTerminalRunner.java    From apdu4j with MIT License 5 votes vote down vote up
public static boolean waitForCard(CardTerminal t, int seconds) throws CardException {
    logger.trace("Waiting for card...");
    final int dot = 3;
    final int n = seconds / dot;
    boolean found = false;
    System.err.print("\nWaiting for card ...");
    for (int i = 0; i < n && !found && !Thread.currentThread().isInterrupted(); i++) {
        found = t.waitForCardPresent(dot * 1000);
        System.err.print(".");
    }
    System.err.println();
    return found;
}