Example usage for java.util Scanner hasNextInt

List of usage examples for java.util Scanner hasNextInt

Introduction

In this page you can find the example usage for java.util Scanner hasNextInt.

Prototype

public boolean hasNextInt() 

Source Link

Document

Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the #nextInt method.

Usage

From source file:com.wandrell.example.swss.client.console.ConsoleClient.java

/**
 * Returns an integer value read from the input.
 * <p>//w  w w  .  ja  va2s. com
 * This will try to parse an integer until one is found, rejecting all the
 * invalid lines.
 *
 * @param scanner
 *            scanner for the input
 * @return an integer read from the input
 */
private static final Integer getInteger(final Scanner scanner) {
    Integer integer; // Parsed integer
    Boolean valid; // Status flag for the loop

    valid = false;
    integer = null;
    while (!valid) {
        // Runs until an integer is found
        valid = scanner.hasNextInt();
        if (valid) {
            // Found an integer
            integer = scanner.nextInt();
        } else {
            // The line is not an integer
            // It is rejected
            scanner.nextLine();
        }
    }

    return integer;
}

From source file:fr.vdl.android.holocolors.HoloColorsDialog.java

private void checkLicence() {
    try {//from  ww  w  .jav a2s . co  m
        String userHome = System.getProperty("user.home");
        File holoColorsFolder = new File(userHome + File.separator + ".holocolors");
        File licenceFile = new File(holoColorsFolder, ".licence");
        File noDonationFile = new File(holoColorsFolder, ".nodonation");

        if (noDonationFile.exists()) {
            return;
        }

        int usage = 1;
        boolean showPopup = false;
        if (!holoColorsFolder.exists()) {
            holoColorsFolder.mkdir();
            showPopup = true;
            licenceFile.createNewFile();
        } else {
            Scanner in = new Scanner(new FileReader(licenceFile));
            if (in.hasNextInt()) {
                usage = in.nextInt() + 1;
            }
            in.close();
        }
        if (usage > 10) {
            usage = 1;
            showPopup = true;
        }
        Writer out = new BufferedWriter(new FileWriter(licenceFile));
        out.write(String.valueOf(usage));
        out.close();

        if (showPopup) {
            Object[] donationOption = { "Make a donation", "Maybe later", "No Never" };
            int option = JOptionPane.showOptionDialog(ahcPanel,
                    "Thanks for using Android Holo Colors!\n\nAndroid Holo Colors (website and plugin) is free to use.\nIf you save time and money with it, please make a donation.",
                    "Support Android Holo Colors", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                    new ImageIcon(getClass().getResource("/icons/H64.png")), donationOption, donationOption[0]);
            if (option == 0) {
                openWebpage(
                        "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XQSBX55A2Z46U");
            }
            if (option == 2) {
                noDonationFile.createNewFile();
            }
        }
    } catch (Exception e) {
        // no matter, nothing to do
        e.printStackTrace();
    }
}

From source file:com.flexive.faces.beans.QueryEditorBean.java

private void joinSelectedNodes(QueryOperatorNode.Operator operator) {
    Scanner scanner = new Scanner(nodeSelection).useDelimiter(",");
    List<Integer> nodeIds = new ArrayList<Integer>();
    while (scanner.hasNextInt()) {
        nodeIds.add(scanner.nextInt());//from w  ww . ja  va  2s  .co m
    }
    if (nodeIds.size() > 1) {
        getRootNode().joinNodes(nodeIds, operator);
    }
    FxJsf1Utils.resetFaceletsComponent(RESET_COMPONENT_ID);
    updateQueryStore();
}

From source file:com.anuta.internal.YangHelperMojo.java

private double versionCompare(String version1, String version2) {
    Scanner v1Scanner = new Scanner(version1);
    Scanner v2Scanner = new Scanner(version2);
    v1Scanner.useDelimiter("\\.");
    v2Scanner.useDelimiter("\\.");

    while (v1Scanner.hasNextInt() && v2Scanner.hasNextInt()) {
        int v1 = v1Scanner.nextInt();
        int v2 = v2Scanner.nextInt();
        if (v1 < v2) {
            return -1;
        } else if (v1 > v2) {
            return 1;
        }/*  w ww . ja  v  a 2s.  c om*/
    }

    if (v1Scanner.hasNextInt()) {
        return 1;
    } else if (v2Scanner.hasNextInt()) {
        return -1;
    } else {
        return 0;
    }
}

From source file:mase.MaseManagerTerminal.java

public void run(File runnersFile, File jobsFile) {
    try {/*from  ww w .j av a2 s  . co m*/
        if (runnersFile != null) {
            mng.loadRunners(runnersFile);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    try {
        if (jobsFile != null) {
            mng.loadJobs(jobsFile);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    final Scanner lineSC = new Scanner(System.in);

    while (true) {
        System.out.print("> ");
        String option = lineSC.next();
        Scanner sc = new Scanner(lineSC.nextLine());
        try {
            switch (option) {
            case "addrunner":
                mng.addRunner(sc.nextLine());
                break;
            case "loadrunners":
                while (sc.hasNext()) {
                    mng.loadRunners(new File(sc.next()));
                }
                break;
            case "addjobs":
                mng.addJob(sc.nextLine());
                break;
            case "loadjobs":
                while (sc.hasNext()) {
                    mng.loadJobs(new File(sc.next()));
                }
                break;
            case "remove":
                while (sc.hasNext()) {
                    mng.removeFromWaiting(sc.next());
                }
                break;
            case "killrunner":
                while (sc.hasNextInt()) {
                    mng.killRunner(sc.nextInt());
                }
                break;
            case "kill":
                while (sc.hasNext()) {
                    mng.killJob(sc.next());
                }
                break;
            case "killall":
                mng.failed.addAll(mng.waitingList);
                mng.waitingList.clear();
                List<Job> running = new ArrayList<>(mng.running.values());
                for (Job j : running) {
                    mng.killJob(j.id);
                }
                break;
            case "output":
                int id = sc.nextInt();
                int l = sc.hasNextInt() ? sc.nextInt() : lines;
                System.out.println(mng.getOutput(id, l));
                break;
            case "jobs":
                while (sc.hasNext()) {
                    String jobid = sc.next();
                    List<Job> found = mng.findJobs(jobid);
                    for (Job j : found) {
                        System.out.println(j.detailedToString() + "\n-----------------");
                    }
                }
                break;
            case "status":
                int ls = sc.hasNextInt() ? sc.nextInt() : lines;
                System.out.println("Completed: " + mng.completed.size() + "\tWaiting: " + mng.waitingList.size()
                        + "\tFailed: " + mng.failed.size() + "\tRunning: " + mng.running.size() + "/"
                        + mng.runners.size() + " " + (mng.runningStatus() ? "(ACTIVE)" : "(PAUSED)"));
                for (Entry<JobRunner, Job> e : mng.running.entrySet()) {
                    System.out.println("== " + e.getValue() + " @ " + e.getKey() + " ========");
                    System.out.println(mng.getOutput(e.getKey().id, ls));
                }
                break;
            case "list":
                while (sc.hasNext()) {
                    String t = sc.next();
                    if (t.equals("failed")) {
                        for (int i = mng.failed.size() - 1; i >= 0; i--) {
                            Job j = mng.failed.get(i);
                            System.out.println(df.format(j.submitted) + " " + j);
                        }
                    } else if (t.equals("completed")) {
                        for (int i = mng.completed.size() - 1; i >= 0; i--) {
                            Job j = mng.completed.get(i);
                            System.out.println(df.format(j.submitted) + " " + j);
                        }
                    } else if (t.equals("waiting")) {
                        for (int i = mng.waitingList.size() - 1; i >= 0; i--) {
                            Job j = mng.waitingList.get(i);
                            System.out.println(df.format(j.submitted) + " " + j);
                        }
                    } else if (t.equals("runners")) {
                        for (JobRunner r : mng.runners.values()) {
                            if (mng.running.containsKey(r)) {
                                Job runningJob = mng.running.get(r);
                                System.out
                                        .println(df.format(runningJob.started) + " " + r + " @ " + runningJob);
                            } else {
                                System.out.println("Idle     " + r);
                            }
                        }
                    } else {
                        error("Unknown list: " + t);
                    }
                }
                break;
            case "retry":
                while (sc.hasNext()) {
                    mng.retryJob(sc.next());
                }
                break;
            case "retryfailed":
                mng.retryFailed();
                break;
            case "clear":
                while (sc.hasNext()) {
                    String t = sc.next();
                    if (t.equals("failed")) {
                        mng.failed.clear();
                    } else if (t.equals("completed")) {
                        mng.completed.clear();
                    } else if (t.equals("waiting")) {
                        mng.waitingList.clear();
                    } else if (t.equals("runners")) {
                        List<Integer> runners = new ArrayList<>(mng.runners.keySet());
                        for (Integer r : runners) {
                            mng.killRunner(r);
                        }
                    } else {
                        error("Unknown list: " + t);
                    }
                }
                break;
            case "priority":
                String type = sc.next();
                while (sc.hasNext()) {
                    String i = sc.next();
                    if (type.equals("top")) {
                        mng.topPriority(i);
                    } else if (type.equals("bottom")) {
                        mng.lowestPriority(i);
                    }
                }
                break;
            case "sort":
                String sort = sc.next();
                if (sort.equals("job")) {
                    mng.sortJobFirst();
                } else if (sort.equals("date")) {
                    mng.sortSubmissionDate();
                } else {
                    error("Unknown sorting method: " + sort);
                }
                break;
            case "pause":
                mng.pause(sc.hasNext() && sc.next().equals("force"));
                break;
            case "start":
                mng.resume();
                break;
            case "exit":
                System.exit(0);
                break;
            case "set":
                String par = sc.next();
                switch (par) {
                case "lines":
                    lines = sc.nextInt();
                    break;
                case "maxtries":
                    mng.setMaxTries(sc.nextInt());
                    break;
                }

                break;
            case "mute":
                this.mute = true;
                break;
            case "unmute":
                this.mute = false;
                break;
            case "help":
                System.out.println("Available commands:\n" + "-- addrunner      runner_type [config]\n"
                        + "-- loadrunners    [file]...\n" + "-- addjobs        job_params\n"
                        + "-- loadjobs       [file]...\n" + "-- killrunner     [runner_id]...\n"
                        + "-- remove         [job_id]...\n" + "-- kill           [job_id]...\n"
                        + "-- killall        \n" + "-- output         runner_id [lines]\n"
                        + "-- jobs           [job_id]...\n" + "-- status         [lines]\n"
                        + "-- list           [waiting|completed|failed|runners]...\n"
                        + "-- retry          [job_id]...\n" + "-- retryfailed    \n"
                        + "-- priority       top|bottom [job_id]...\n" + "-- sort           batch|job|date\n"
                        + "-- clear          [waiting|completed|failed|runners]...\n"
                        + "-- pause          [force]\n" + "-- start          \n" + "-- mute|unmute    \n"
                        + "-- exit           \n" + "-- set            lines|tries value");
                break;
            default:
                System.out.println("Unknown command. Try help.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:edu.uci.ics.asterix.transaction.management.service.locking.LockManagerDeterministicUnitTest.java

public void readRequest() throws IOException, ACIDException {
    int i = 0;//from w  w w .j  a v  a 2s . c o  m
    LockRequest lockRequest = null;
    TransactionContext txnContext = null;
    HashMap<Integer, TransactionContext> jobMap = new HashMap<Integer, TransactionContext>();

    int threadId;
    String requestType;
    int jobId;
    int datasetId;
    int PKHashVal;
    int waitTime;
    ArrayList<Integer> list = null;
    String lockMode;

    Scanner scanner = new Scanner(new FileInputStream(requestFileName));
    while (scanner.hasNextLine()) {
        try {
            threadId = Integer.parseInt(scanner.next().substring(1));
            requestType = scanner.next();
            if (requestType.equals("CSQ") || requestType.equals("CST") || requestType.equals("END")) {
                log("LockRequest[" + i++ + "]:T" + threadId + "," + requestType);
                lockRequest = new LockRequest("Thread-" + threadId, getRequestType(requestType));
                if (requestType.equals("CSQ") || requestType.equals("CST")) {
                    list = new ArrayList<Integer>();
                    while (scanner.hasNextInt()) {
                        threadId = scanner.nextInt();
                        if (threadId < 0) {
                            break;
                        }
                        list.add(threadId);
                    }
                    expectedResultList.add(list);
                }
            } else if (requestType.equals("DW")) {
                defaultWaitTime = scanner.nextInt();
                log("LockRequest[" + i++ + "]:T" + threadId + "," + requestType + "," + defaultWaitTime);
                continue;
            } else if (requestType.equals("W")) {
                waitTime = scanner.nextInt();
                log("LockRequest[" + i++ + "]:T" + threadId + "," + requestType);
                lockRequest = new LockRequest("Thread-" + threadId, getRequestType(requestType), waitTime);
            } else {
                jobId = Integer.parseInt(scanner.next().substring(1));
                datasetId = Integer.parseInt(scanner.next().substring(1));
                PKHashVal = Integer.parseInt(scanner.next().substring(1));
                lockMode = scanner.next();
                txnContext = jobMap.get(jobId);
                if (txnContext == null) {
                    txnContext = new TransactionContext(new JobId(jobId), txnProvider);
                    jobMap.put(jobId, txnContext);
                }
                log("LockRequest[" + i++ + "]:T" + threadId + "," + requestType + ",J" + jobId + ",D"
                        + datasetId + ",E" + PKHashVal + "," + lockMode);
                lockRequest = new LockRequest("Thread-" + threadId, getRequestType(requestType),
                        new DatasetId(datasetId), PKHashVal, getLockMode(lockMode), txnContext);
            }

            requestList.add(lockRequest);
        } catch (NoSuchElementException e) {
            scanner.close();
            break;
        }
    }
}

From source file:com.axelor.studio.service.builder.FormBuilderService.java

private Iterator<ViewPanel> sortPanels(List<ViewPanel> viewPanelList) {

    Collections.sort(viewPanelList, new Comparator<ViewPanel>() {

        @Override/* ww w.  j  a  v a  2 s .  c om*/
        public int compare(ViewPanel panel1, ViewPanel panel2) {
            Scanner scan1 = new Scanner(panel1.getPanelLevel());
            Scanner scan2 = new Scanner(panel2.getPanelLevel());
            scan1.useDelimiter("\\.");
            scan2.useDelimiter("\\.");
            try {
                while (scan1.hasNextInt() && scan2.hasNextInt()) {
                    int v1 = scan1.nextInt();
                    int v2 = scan2.nextInt();
                    if (v1 < v2) {
                        return -1;
                    } else if (v1 > v2) {
                        return 1;
                    }
                }

                if (scan2.hasNextInt()) {
                    return -1;
                }
                if (scan1.hasNextInt()) {
                    return 1;
                }

                return 0;
            } finally {
                scan1.close();
                scan2.close();
            }

        }
    });

    return viewPanelList.iterator();
}

From source file:codeu.chat.client.commandline.Chat.java

public String doOneTestCommand(Scanner lineScanner) {
    final Scanner tokenScanner = new Scanner(lineScanner.nextLine());
    if (!tokenScanner.hasNext()) {
        return "";
    }/*from w  w  w.j  a v a  2 s . co  m*/
    final String token = tokenScanner.next();

    if (token.equals("exit")) {

        alive = false;

    } else if (token.equals("help")) {

        help();

    } else if (token.equals("sign-in")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: No user name supplied.");
        } else {
            signInUser(tokenScanner.nextLine().trim());

            // Automatically create the bot user and the conversation with the bot once a user signs in
            if (clientContext.user.lookup(BOT_NAME) == null) // Check whether the bot and convo already exist
            {
                addUser(BOT_NAME);
                clientContext.conversation.startConversation(BOT_CONVO, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("sign-out")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            signOutUser();
        }

    } else if (token.equals("current")) {

        showCurrent();

    } else if (token.equals("u-add")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: Username not supplied.");
        } else {
            addUser(tokenScanner.nextLine().trim());
        }

    } else if (token.equals("u-list-all")) {

        showAllUsers();

    } else if (token.equals("c-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Conversation title not supplied.");
            } else {
                final String title = tokenScanner.nextLine().trim();
                clientContext.conversation.startConversation(title, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("c-list-all")) {

        clientContext.conversation.showAllConversations();

    } else if (token.equals("c-select")) {

        selectConversation(lineScanner);

    } else if (token.equals("m-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Message body not supplied.");
            } else {
                final String body = tokenScanner.nextLine().trim();
                clientContext.message.addMessage(clientContext.user.getCurrent().id,
                        clientContext.conversation.getCurrentId(), body);

                respondAsBot(body, false);
            }
        }

    } else if (token.equals("m-list-all")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            clientContext.message.showAllMessages();
        }

    } else if (token.equals("m-next")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNextInt()) {
            System.out.println("Command requires an integer message index.");
        } else {
            clientContext.message.selectMessage(tokenScanner.nextInt());
        }

    } else if (token.equals("m-show")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            final int count = (tokenScanner.hasNextInt()) ? tokenScanner.nextInt() : 1;
            clientContext.message.showMessages(count);
        }

    } else {

        System.out.format("Command not recognized: %s\n", token);
        System.out.format("Command line rejected: %s%s\n", token,
                (tokenScanner.hasNext()) ? tokenScanner.nextLine() : "");
        System.out.println("Type \"help\" for help.");
    }
    tokenScanner.close();
    return response;
}

From source file:codeu.chat.client.commandline.Chat.java

private void doOneCommand(Scanner lineScanner) {

    final Scanner tokenScanner = new Scanner(lineScanner.nextLine());
    if (!tokenScanner.hasNext()) {
        return;//from   w  w w  .  j  ava2  s  . com
    }
    final String token = tokenScanner.next();

    if (token.equals("exit")) {

        alive = false;

    } else if (token.equals("help")) {

        help();

    } else if (token.equals("sign-in")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: No user name supplied.");
        } else {
            signInUser(tokenScanner.nextLine().trim());

            // Check whether the bot/convo already exist
            if (clientContext.user.lookup(BOT_NAME) == null) {
                addUser(BOT_NAME);
                clientContext.conversation.startConversation(BOT_CONVO, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("sign-out")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            signOutUser();
        }

    } else if (token.equals("current")) {

        showCurrent();

    } else if (token.equals("u-add")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: Username not supplied.");
        } else {
            addUser(tokenScanner.nextLine().trim());
        }

    } else if (token.equals("u-list-all")) {

        showAllUsers();

    } else if (token.equals("c-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Conversation title not supplied.");
            } else {
                final String title = tokenScanner.nextLine().trim();
                clientContext.conversation.startConversation(title, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("c-list-all")) {

        clientContext.conversation.showAllConversations();

    } else if (token.equals("c-select")) {

        selectConversation(lineScanner);

    } else if (token.equals("c-search-title")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: Conversation title not supplied.");
        } else {
            final String title = tokenScanner.nextLine().trim();
            clientContext.conversation.searchTitle(title);
        }

    } else if (token.equals("m-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Message body not supplied.");
            } else {
                final String body = tokenScanner.nextLine().trim();
                clientContext.message.addMessage(clientContext.user.getCurrent().id,
                        clientContext.conversation.getCurrentId(), body);

                respondAsBot(body, true);
            }
        }

    } else if (token.equals("m-list-all")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            clientContext.message.showAllMessages();
        }

    } else if (token.equals("m-next")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNextInt()) {
            System.out.println("Command requires an integer message index.");
        } else {
            clientContext.message.selectMessage(tokenScanner.nextInt());
        }

    } else if (token.equals("m-show")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            final int count = (tokenScanner.hasNextInt()) ? tokenScanner.nextInt() : 1;
            clientContext.message.showMessages(count);
        }

    } else if (token.equals("m-search-string")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: String not supplied.");
        } else {
            final String keyword = tokenScanner.nextLine().trim();
            clientContext.message.searchString(keyword);
        }

    } else if (token.equals("m-search-author")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: author body not supplied.");
        } else {
            final String author = tokenScanner.nextLine().trim();
            clientContext.message.searchAuthor(author);
        }

    } else if (token.equals("t-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: tag name not supplied.");
            } else {
                final String name = tokenScanner.nextLine().trim();
                clientContext.tag.addTag(clientContext.user.getCurrent().id, name);
            }
        }

    } else if (token.equals("t-list")) {
        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: tag name not supplied.");
            } else {
                final String name = tokenScanner.nextLine().trim();
                clientContext.tag.listTag(clientContext.user.getCurrent().id, name);
            }
        }

    } else if (token.equals("t-list-all")) {
        showAllTags();

    } else if (token.equals("t-list-user")) {
        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            clientContext.tag.showUserTags(clientContext.user.getCurrent().id);
        }
    } else {
        System.out.format("Command not recognized: %s\n", token);
        System.out.format("Command line rejected: %s%s\n", token,
                (tokenScanner.hasNext()) ? tokenScanner.nextLine() : "");
        System.out.println("Type \"help\" for help.");
    }
    tokenScanner.close();
}

From source file:org.apache.hadoop.yarn.server.nodemanager.util.TestCgroupsLCEResourcesHandler.java

private int readIntFromFile(File targetFile) throws IOException {
    Scanner scanner = new Scanner(targetFile);
    try {//from  www  .j  av  a 2  s. c  o  m
        return scanner.hasNextInt() ? scanner.nextInt() : -1;
    } finally {
        scanner.close();
    }
}