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:OpenCalaisGenerateRdfPropertiesFromWebPages.java

public OpenCalaisGenerateRdfPropertiesFromWebPages(String config_file_path, PrintWriter out)
        throws IOException {
    this.out = out;
    List<String> lines = (List<String>) FileUtils.readLines(new File(config_file_path));
    for (String line : lines) {
        Scanner scanner = new Scanner(line);
        scanner.useDelimiter(" ");
        try {/*  ww  w.  j  a  v a 2s .c  o  m*/
            String starting_url = scanner.next();
            int spider_depth = Integer.parseInt(scanner.next());
            spider(starting_url, spider_depth);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    this.out.close();
}

From source file:hu.sztaki.incremental.ml.streaming.imsr.MatrixVectorPairSource.java

@Override
public void invoke(Collector<Tuple2<double[][], double[][]>> out) throws Exception {
    File f = new File(path);
    if (!f.exists()) {
        System.err.println(path + " does not exist.");
        System.exit(1);//from w ww  .  ja  v a  2  s .  c om
    }
    Scanner s = initCsvScanner(new Scanner(f));
    String firstLine = s.nextLine();
    Scanner firstLineScanner = initCsvScanner(new Scanner(firstLine));
    for (indepDim = 0; firstLineScanner.hasNext(); firstLineScanner.next(), indepDim++)
        ;
    indepDim--;
    while (s.hasNext()) {
        Array2DRowRealMatrix X = new Array2DRowRealMatrix(batchSize, indepDim);
        Array2DRowRealMatrix y = new Array2DRowRealMatrix(batchSize, 1);
        readMatricesSideBySide(s, X, y);
        out.collect(new Tuple2<double[][], double[][]>(X.getDataRef(), y.getDataRef()));
    }
    s.close();
    out.close();
}

From source file:de.bley.word.menu.Menue.java

protected void writeFrile(final Scanner scan) {
    try {/*w ww . j av  a2 s .c  o  m*/
        zuordnung.getAusgabe().ausgeben("output:");
        String output = scan.next();
        zuordnung.getWriter().writeInFile(zuordnung.getPath().getFilepath(), output, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.cefetrj.sagitarii.nunki.comm.WebClient.java

private String convertStreamToString(java.io.InputStreamReader is) {
    java.util.Scanner s = new java.util.Scanner(is);
    s.useDelimiter("\\A");
    String retorno = s.hasNext() ? s.next() : "";
    s.close();//from  w  ww  .  j a va 2s  .c  om
    return retorno;
}

From source file:com.sonicle.webtop.core.versioning.SqlScript.java

private void readFile(InputStreamReader readable) throws IOException {
    this.statements = new ArrayList<>();
    String lines[] = null;//from   w w  w . ja va 2s  .c  om
    StringBuilder sbsql = null;

    Scanner s = new Scanner(readable);
    s.useDelimiter("(;( )?(\r)?\n)");
    while (s.hasNext()) {
        String block = s.next();
        block = StringUtils.replace(block, "\r", "");
        if (!StringUtils.isEmpty(block)) {
            // Remove remaining ; at the end of the block (only if this block is the last one)
            if (!s.hasNext() && StringUtils.endsWith(block, ";"))
                block = StringUtils.left(block, block.length() - 1);

            sbsql = new StringBuilder();
            lines = StringUtils.split(block, "\n");
            for (String line : lines) {
                if (CommentLine.matches(line))
                    continue;
                sbsql.append(StringUtils.trim(line));
                sbsql.append(" ");
            }
            if (sbsql.length() > 0)
                statements.add(sbsql.toString());
        }
    }
}

From source file:simulation.AureoZauleckAnsLab2.java

public static ArrayList GetData2() {
    N = 0;//from   ww  w .java  2s  .  c  om

    ArrayList<Double> list = new ArrayList<>();
    Scanner sc = new Scanner(System.in);
    String testN = "";
    int population = 0;
    do {
        System.out.println();
        System.out.println("Enter the maximun number of inputs: ");

        testN = sc.next();

        if (IsNumber(testN)) {
            population = Convert(testN);
        } else {
            do {
                System.out.println("Please enter a number only.");
                testN = sc.next();
            } while (!IsNumber(testN));

            population = Convert(testN);
        }
        N = population;
    } while (N <= 1);

    String test = "";

    for (int i = 1; i <= N; i++) {
        do {
            System.out.print("[" + i + "]" + " ");
            Object member = sc.next();
            test = member.toString();
            if (!IsNumber(test)) {
                System.out.println("Oops. Numbers only");
            }
        } while (!IsNumber(test));

        Double converted = 0.0;
        converted = Double.parseDouble(test);
        list.add(converted);

    }
    System.out.println("this is the list" + list);
    return list;
}

From source file:com.currencyfair.minfraud.MinFraudImpl.java

private Map<String, String> parseValueMap(String responseValues) {
    Map<String, String> pairs = new LinkedHashMap<>();
    Scanner scanner = new Scanner(responseValues).useDelimiter("[;=]");
    try {//from w  w w  . jav  a2s. co m
        while (scanner.hasNext()) {
            pairs.put(scanner.next(), scanner.next());
        }
    } catch (NoSuchElementException x) {
        LOG.warn("Unbalanced response received from remote: {}", responseValues);
    }
    return ValueUtils.removeEmptyValues(pairs);
}

From source file:fr.itldev.koya.services.impl.util.AlfrescoRestErrorHandler.java

@Override
public void handleError(ClientHttpResponse clienthttpresponse) throws IOException {

    if (!statusOK.contains(clienthttpresponse.getStatusCode())) {
        AlfrescoServiceException ex;//from w  w w . j  a  v  a2s  .co  m
        if (clienthttpresponse.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
            java.util.Scanner s = new java.util.Scanner(clienthttpresponse.getBody()).useDelimiter("\\A");
            String message = s.hasNext() ? s.next() : "";

            /*
             Try to get any Koya Error code if exists
             */
            Integer koyaErrorCode = null;

            Matcher matcher = ERRORCODEPATTERN.matcher(message);
            if (matcher.find()) {
                koyaErrorCode = Integer.valueOf(matcher.group(1));
            }

            ex = new AlfrescoServiceException(
                    "Erreur " + clienthttpresponse.getStatusCode() + " : " + clienthttpresponse.getStatusText(),
                    koyaErrorCode);
            ex.setHttpErrorCode(clienthttpresponse.getStatusCode().value());
        } else if (clienthttpresponse.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
            ex = new AlfrescoServiceException("Acces Denied");
            ex.setHttpErrorCode(clienthttpresponse.getStatusCode().value());

        } else {
            ex = new AlfrescoServiceException();
            ex.setHttpErrorCode(clienthttpresponse.getStatusCode().value());
            throw ex;
        }
        throw ex;

    }
}

From source file:org.openvoters.android.tasks.RemoteAPIGetListTask.java

@Override
protected JSONObject doInBackground(RemoteAPIGetListCallback... params) {
    if (params.length > 0) {
        callback = params[0];/* ww w  . j a v  a 2 s  .  c o m*/
    }

    JSONObject result = null;
    AndroidHttpClient httpClient = AndroidHttpClient.newInstance("");

    try {
        HttpGet request = new HttpGet(String.format("%s/%s", RemoteAPI.getBaseURL(), "getlist"));
        HttpResponse response = httpClient.execute(request);

        InputStream input = response.getEntity().getContent();
        java.util.Scanner s = new java.util.Scanner(input).useDelimiter("\\A");
        String responseString = s.hasNext() ? s.next() : "";

        JSONObject obj = new JSONObject(responseString);
        httpClient.close();
        result = obj;
    } catch (Exception e) {
        httpClient.close();
        taskError = true;
        exc = e;
        return null;
    }

    httpClient.close();

    elabora(result);
    return result;
}

From source file:com.spend.spendService.MainPage.java

private String getSearchQuery() {
    Scanner s = new Scanner(System.in);
    System.out.print("Enter query : ");
    searchQuery = s.next();
    return searchQuery;
}