Example usage for java.util Scanner next

List of usage examples for java.util Scanner next

Introduction

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

Prototype

public String next() 

Source Link

Document

Finds and returns the next complete token from this scanner.

Usage

From source file:com.android.idtt.http.client.util.URLEncodedUtils.java

/**
 * Adds all parameters within the Scanner to the list of
 * <code>parameters</code>, as encoded by <code>encoding</code>. For
 * example, a scanner containing the string <code>a=1&b=2&c=3</code> would
 * add the {@link org.apache.http.NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
 * list of parameters./* w ww. ja  v a  2 s . c o  m*/
 *
 * @param parameters List to add parameters to.
 * @param scanner    Input that contains the parameters to parse.
 * @param charset    Encoding to use when decoding the parameters.
 */
public static void parse(final List<NameValuePair> parameters, final Scanner scanner, final String charset) {
    scanner.useDelimiter(PARAMETER_SEPARATOR);
    while (scanner.hasNext()) {
        String name = null;
        String value = null;
        String token = scanner.next();
        int i = token.indexOf(NAME_VALUE_SEPARATOR);
        if (i != -1) {
            name = decodeFormFields(token.substring(0, i).trim(), charset);
            value = decodeFormFields(token.substring(i + 1).trim(), charset);
        } else {
            name = decodeFormFields(token.trim(), charset);
        }
        parameters.add(new BasicNameValuePair(name, value));
    }
}

From source file:org.apache.james.filesystem.api.SieveFileRepository.java

/**
 * Read a file with the specified encoding into a String
 *
 * @param file/*from  w  ww  .j  a  va 2  s .c om*/
 * @param encoding
 * @return
 * @throws FileNotFoundException
 */
static protected String toString(File file, String encoding) throws FileNotFoundException {
    String script = null;
    Scanner scanner = null;
    try {
        scanner = new Scanner(file, encoding).useDelimiter("\\A");
        script = scanner.next();
    } finally {
        if (null != scanner) {
            scanner.close();
        }
    }
    return script;
}

From source file:utils.APIExporter.java

static void singleApiExport(String consumerCredentials) throws APIExportException {
    ApiImportExportConfiguration config = ApiImportExportConfiguration.getInstance();

    Scanner scanner = new Scanner(System.in, ImportExportConstants.CHARSET);
    if (StringUtils.isBlank(config.getApiName())) {
        System.out.print("Enter the name of the API been export : ");
        String name = scanner.next();
        if (StringUtils.isNotBlank(name)) {
            config.setApiName(name);/*from  w w  w  .  ja  v a 2 s  .c  om*/
        }
    }
    if (StringUtils.isBlank(config.getApiProvider())) {
        System.out.print("Enter the provider of the API been export : ");
        String provider = scanner.next();
        if (StringUtils.isNotBlank(provider)) {
            config.setApiProvider(provider);
        }
    }
    if (StringUtils.isBlank(config.getApiVersion())) {
        System.out.print("Enter the version of the API been export : ");
        String version = scanner.next();
        if (StringUtils.isNotBlank(version)) {
            config.setApiVersion(version);
        }
    }

    //generating access token
    String token = ImportExportUtils.getAccessToken(ImportExportConstants.EXPORT_SCOPE, consumerCredentials);
    if (StringUtils.isBlank(token)) {
        String errorMsg = "Error occured while generating the access token for API Export ";
        log.error(errorMsg);
        throw new APIExportException(errorMsg);
    }
    //exporting the API
    String zipLocation = getDestinationFolder(config);
    exportAPI(zipLocation, config.getApiName(), config.getApiProvider(), config.getApiVersion(), token);
    //archiving the directory
    ArchiveGeneratorUtil.archiveDirectory(zipLocation);
}

From source file:com.gistlabs.mechanize.util.apache.URLEncodedUtils.java

/**
 * Adds all parameters within the Scanner to the list of
 * <code>parameters</code>, as encoded by <code>encoding</code>. For
 * example, a scanner containing the string <code>a=1&b=2&c=3</code> would
 * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
 * list of parameters./*from www .j a va2 s .com*/
 *
 * @param parameters
 *            List to add parameters to.
 * @param scanner
 *            Input that contains the parameters to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 */
public static void parse(final List<NameValuePair> parameters, final Scanner scanner, final String charset) {
    scanner.useDelimiter(PARAMETER_SEPARATOR);
    while (scanner.hasNext()) {
        String name = null;
        String value = null;
        String token = scanner.next();
        int i = token.indexOf(NAME_VALUE_SEPARATOR);
        if (i != -1) {
            name = decodeFormFields(token.substring(0, i).trim(), charset);
            value = decodeFormFields(token.substring(i + 1).trim(), charset);
        } else
            name = decodeFormFields(token.trim(), charset);
        parameters.add(new BasicNameValuePair(name, value));
    }
}

From source file:com.qmetry.qaf.automation.testng.report.ReporterUtil.java

public static String execHostName(String execCommand) {
    InputStream stream;/* w ww.  j a v a  2 s. c  o  m*/
    Scanner s;
    try {
        Process proc = Runtime.getRuntime().exec(execCommand);
        stream = proc.getInputStream();
        if (stream != null) {
            s = new Scanner(stream);
            s.useDelimiter("\\A");
            String val = s.hasNext() ? s.next() : "";
            stream.close();
            s.close();
            return val;
        }
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }
    return "";
}

From source file:net.firejack.platform.core.config.meta.construct.ConfigElementFactory.java

private static boolean allWordsCapitalized(String value) {
    Scanner sc = new Scanner(value);
    while (sc.hasNext()) {
        String word = sc.next();
        if (!StringUtils.capitalize(word).equals(word)) {
            return false;
        }// ww w. jav a2s .c  o m
    }
    return true;
}

From source file:br.ufrgs.inf.dsmoura.repository.controller.solr.SolrConversionUtil.java

public static String fromStringToQuery(String value) {
    String query = "";
    boolean isOpenedQuote = false;
    Scanner sc = new Scanner(value);
    while (sc.hasNext()) {
        String next = sc.next();
        if (next.contains("\"") || isOpenedQuote) {
            query += next;// w  w  w. j  ava2 s .  c o  m
            if (next.contains("\"")) {
                isOpenedQuote = !isOpenedQuote;
            }
        } else {
            if (next.contains(":")) {
                query += next.replace(":", ":*") + "*";
            } else {
                query += "*" + next + "*";
            }
        }
        if (!isOpenedQuote) {
            query += " OR ";
        } else {
            query += " ";
        }
    }
    if (query.endsWith(" OR ")) {
        return query.substring(0, query.lastIndexOf(" OR "));
    } else {
        return query;
    }
}

From source file:com.microsoft.intellij.util.WAHelper.java

/**
 * This API compares if two files content is identical. It ignores extra
 * spaces and new lines while comparing/*from ww w  . j  av a 2 s  . c o m*/
 *
 * @param sourceFile
 * @param destFile
 * @return
 * @throws Exception
 */
public static boolean isFilesIdentical(URL sourceFile, File destFile) throws Exception {
    try {
        Scanner sourceFileScanner = new Scanner(sourceFile.openStream());
        Scanner destFileScanner = new Scanner(destFile);

        while (sourceFileScanner.hasNext()) {
            /*
             * If source file is having next token then destination file
            * also should have next token, else they are not identical.
            */
            if (!destFileScanner.hasNext()) {
                destFileScanner.close();
                sourceFileScanner.close();
                return false;
            }
            if (!sourceFileScanner.next().equals(destFileScanner.next())) {
                sourceFileScanner.close();
                destFileScanner.close();
                return false;
            }
        }
        /*
        * Handling the case where source file is empty and destination file
        * is having text
        */
        if (destFileScanner.hasNext()) {
            destFileScanner.close();
            sourceFileScanner.close();
            return false;
        } else {
            destFileScanner.close();
            sourceFileScanner.close();
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } /*finally {
      sourceFile.close();
      }*/
}

From source file:br.ufrgs.inf.dsmoura.repository.controller.solr.SolrConversionUtil.java

private static List<Term> extractTerms(String fieldName, String value, boolean doubleQuote) {
    if ((value == null) || (value.trim().length() == 0)) {
        return new ArrayList<Term>();
    }/*ww w. ja v  a2s  . c o  m*/
    if (fieldName == null) {
        throw new RuntimeException("null fieldName");
    }
    if (doubleQuote) {
        /* Value between double quotes */
        List<Term> terms = new ArrayList<Term>();
        terms.add(new Term(fieldName, '\"' + value + '\"'));
        return terms;
    } else {
        /* Value between wildcards */
        List<Term> terms = new ArrayList<Term>();
        Scanner sc = new Scanner(value);
        while (sc.hasNext()) {
            terms.add(new Term(fieldName, "*" + sc.next() + "*"));
        }
        return terms;
    }
}

From source file:com.mcxiaoke.next.http.util.URLUtils.java

/**
 * Adds all parameters within the Scanner to the list of
 * <code>parameters</code>, as encoded by <code>encoding</code>. For
 * example, a scanner containing the string <code>a=1&b=2&c=3</code> would
 * add the {@link org.apache.http.NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
 * list of parameters./*from ww  w .  ja v a  2 s.c o m*/
 *
 * @param parameters               List to add parameters to.
 * @param scanner                  Input that contains the parameters to parse.
 * @param parameterSepartorPattern The Pattern string for parameter separators, by convention {@code "[&;]"}
 * @param charset                  Encoding to use when decoding the parameters.
 */
public static void parse(final List<NameValuePair> parameters, final Scanner scanner,
        final String parameterSepartorPattern, final String charset) {
    scanner.useDelimiter(parameterSepartorPattern);
    while (scanner.hasNext()) {
        String name = null;
        String value = null;
        final String token = scanner.next();
        final int i = token.indexOf(NAME_VALUE_SEPARATOR);
        if (i != -1) {
            name = decodeFormFields(token.substring(0, i).trim(), charset);
            value = decodeFormFields(token.substring(i + 1).trim(), charset);
        } else {
            name = decodeFormFields(token.trim(), charset);
        }
        parameters.add(new BasicNameValuePair(name, value));
    }
}