Package java.util

Examples of java.util.Scanner


            throw new IllegalArgumentException(duration+" is not a time type");
        }
        if (duration.endsWith(":")) {
            duration += " ";
        }
        Scanner s = new Scanner(duration);
        int res = 0;
        s.useLocale(Locale.US);//TODO LP: What to do with locale formatted numbers?
        s.useDelimiter(":");
        String val;
        while (s.hasNext()) {
            res = res * 60;
            if (s.hasNextInt()) {
                res += s.nextInt();
            } else {
                s.next();
            }
        }
        s.close();
        return res;
    }
View Full Code Here


    static int getJobVerifyModeAsInt(String firstArg) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
   
    private static boolean isValueValid(String value, String pattern) {
        Scanner s = new Scanner(value);
        try {
            s.next("^("+pattern+")$");
            return true;
        } catch (InputMismatchException ex) {
            return false;
        }
    }
View Full Code Here

    // Currently we accept pattern in list of hosts in a file
    public static List<String> parseFileList(File f) throws FileNotFoundException {
        List<String> hostList = new LinkedList<String>(), tempList;
        Host.Type type;
        Scanner s = new Scanner(f);
        s.useDelimiter("\\s+|;|,");
        String pattern = "";
        while (s.hasNext()) {
            pattern = s.next().toLowerCase().trim();
            type = isIpPattern(pattern) ? Host.Type.IP : Host.Type.HOSTNAME;
            tempList = parsePattern(pattern, type);
            hostList = joinList(hostList, tempList);
        }
        s.close();
        return hostList;
    }
View Full Code Here

        long start=System.currentTimeMillis(),endL;
        LinkedList<List<String>> list = new LinkedList<List<String>>();
        int i=0;
        String elem;

        Scanner s = new Scanner(input);
        s.useDelimiter("\\.");
        while (s.hasNext()) {
            elem = s.next();
            i++;
            switch (type) {
                case HOSTNAME:
                    list.add(parseSinglePattern(elem, type));
                    break;
                case IP:
                    if (elem.charAt(0) >= '0' && elem.charAt(0) <= '9' || elem.charAt(0) == '[') {
                        List<String> singlePattern = parseSinglePattern(elem, type);
                        //Valid IP octed must be in 0 to 255
                        LinkedList<String> finalList = new LinkedList<String>();
                        int j;
                        String temp;
                        for (String val : singlePattern) {
                            j = Integer.valueOf(val).intValue();
                            if (j < 0 || j > 255) {
                                j = Math.max(0, j);
                                j = Math.min(255, j);
                                temp = String.valueOf(j);
                                if (!finalList.contains(temp)) {
                                    finalList.add(temp);
                                }
                            } else if (!finalList.contains(val)) {
                                finalList.add(val);
                            }
                        }
                        list.add(finalList);
                        break;
                    }                 
                default:
                    s.close();
                    throw new IllegalArgumentException("invalid value " + elem + " for type " + type.toString() + ".");
            }
        }
        s.close();

        //Ip must have 4 octects
        if (type == Host.Type.IP && i != 4) {
            throw new IllegalArgumentException("IP must have 4 octects! Got " + i + ".");
        }
View Full Code Here

      path = "usages/System/" + ((OperatorNameProvider) element).getOperatorName() + ".html";
    }

    InputStream docFile = (path != null) ? MathematicaDocumentationProvider.class.getResourceAsStream(path) : null;
    if (docFile != null) {
      return new Scanner(docFile, "UTF-8").useDelimiter("\\A").next();
    }
    return null;
  }
View Full Code Here

        assertThat(actual, is(Arrays.asList(expected)));
    }

    private void test(File file, String... expected) throws IOException {
        List<String> actual = new ArrayList<String>();
        Scanner scanner = new Scanner(file, "UTF-8");
        while (scanner.hasNextLine()) {
            actual.add(scanner.nextLine());
        }
        scanner.close();
        Collections.sort(actual);
        Arrays.sort(expected);
        assertThat(actual, is(Arrays.asList(expected)));
    }
View Full Code Here

     * @return the statements
     * @throws IOException if failed
     */
    protected List<String> collectStatements(File target) throws IOException {
        StringBuilder buf = new StringBuilder();
        Scanner scanner = new Scanner(target, "UTF-8");
        try {
            while (scanner.hasNextLine()) {
                buf.append(scanner.nextLine());
                buf.append('\n');
            }
        } finally {
            scanner.close();
        }
        List<String> results = new ArrayList<String>();
        for (String ql : buf.toString().split(";")) {
            String s = ql.trim();
            if (s.isEmpty() == false) {
View Full Code Here

        Map<String, String> results = new HashMap<String, String>();
        JschConnection conn = new JschConnection(profile, Arrays.asList(profile.getGetCommand()));
        try {
            InputStream output = conn.openStandardOutput();
            conn.connect();
            Scanner s = new Scanner(output, "UTF-8");
            while (s.hasNextLine()) {
                String[] pair = s.nextLine().split("=", 2);
                if (pair.length == 2) {
                    results.put(pair[0], pair[1]);
                }
            }
            s.close();
            int exit = conn.waitForExit(10000);
            assertThat(exit, is(0));
        } finally {
            conn.close();
        }
View Full Code Here

            while (cur.next()) {
                Location location = cur.getLocation();
                InputStream input = cur.openResource();
                try {
                    List<String> contents = Lists.create();
                    Scanner scanner = new Scanner(input, "UTF-8");
                    while (scanner.hasNextLine()) {
                        String line = scanner.nextLine();
                        contents.add(line);
                    }
                    entries.put(location.toPath('/'), contents);
                    scanner.close();
                } finally {
                    input.close();
                }
            }
            return entries;
View Full Code Here

            while (cur.next()) {
                Location location = cur.getLocation();
                InputStream input = cur.openResource();
                try {
                    List<String> contents = Lists.create();
                    Scanner scanner = new Scanner(input, "UTF-8");
                    while (scanner.hasNextLine()) {
                        String line = scanner.nextLine();
                        contents.add(line);
                    }
                    entries.put(location.toPath('/'), contents);
                    scanner.close();
                } finally {
                    input.close();
                }
            }
            return entries;
View Full Code Here

TOP

Related Classes of java.util.Scanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.