Package java.util

Examples of java.util.Scanner


        TestSettings testSettings = new TestSettings("rest/savebulk");
        //testSettings.setPort(9200)
        testSettings.setProperty(ConfigurationOptions.ES_SERIALIZATION_WRITER_VALUE_CLASS, JdkValueWriter.class.getName());
        RestRepository client = new RestRepository(testSettings);

        Scanner in = new Scanner(getClass().getResourceAsStream("/artists.dat")).useDelimiter("\\n|\\t");

        Map<String, String> line = new LinkedHashMap<String, String>();

        for (; in.hasNextLine();) {
            // ignore number
            in.next();
            line.put("name", in.next());
            line.put("url", in.next());
            line.put("picture", in.next());
            client.writeToIndex(line);
            line.clear();
        }

        client.close();
View Full Code Here


            assertEquals("Expecting " + key + "=" + value, value, m.get(key, String.class));
        }
    }

    static String readTextFile(File bodyFile) throws FileNotFoundException {
        Scanner sc = null;
        try {
            sc = new Scanner(bodyFile);
            String expectedBody = "";
            while (sc.hasNextLine()) {
                expectedBody += sc.nextLine() + "\n";
            }
            expectedBody = expectedBody.substring(0, expectedBody.length()-1);
            return expectedBody;
        } finally {
            if (sc != null) {
                sc.close();
            }
        }
    }
View Full Code Here

        return path;
    }

    static void assertHeaders(File headersFile, ModifiableValueMap m) throws FileNotFoundException {
        Map<String, List<String>> expectedHeaders = new HashMap<String, List<String>>();
        Scanner sc = new Scanner(headersFile);
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.startsWith("//"))
                continue;
            String[] colon = line.split(TEST_FILE_FIELD_SEPARATOR);
            String header = colon[0];
            String value = colon[1];
            List<String> values;
            if ((values = expectedHeaders.get(header)) == null) {
                values = new ArrayList<String>();
                expectedHeaders.put(header, values);
            }
            values.add(value);
        }
        sc.close();

        assertEquals("Expecting same number of headers", m.keySet().size()-2, expectedHeaders.keySet().size());
        // -1 for Body (should be no htmlBody)
        // -1 for X-original-header
View Full Code Here

      final Props props = new Props("title", "HELLO", "jcr:text", "world");
      resolver.create(testRoot, "child_" + System.currentTimeMillis(), props).getPath();
      resolver.commit();
    }

    Scanner sc = new Scanner(System.in);
    System.out.println("Type \"quit\" to continue loading MAS.");
    System.out.print("*** New query: >");
    String query = sc.nextLine();
    while (!query.equalsIgnoreCase("quit")) {
      try {
        System.out.println("*** sql");
        Iterator<Resource> resSQL = resolver.findResources(query, Query.JCR_SQL2);
        while (resSQL.hasNext()) {
          Resource resource = (Resource) resSQL.next();
          System.out.println(resource.toString());
        }
       
//        System.out.println("*** xpath");
//        Iterator<Resource> resXPath = resolver.findResources(query, Query.XPATH);
//        while (resXPath.hasNext()) {
//          Resource resource = (Resource) resXPath.next();
//          System.out.println(resource.toString());
//        }

      } catch (Exception e) {
        e.printStackTrace();
      }
     
      System.out.print("*** New query: >");
      query = sc.nextLine();
    }
  }
View Full Code Here

   * @param stream
   *          Open InputStream containing the word for the treeWordList, this method will close the
   *          stream.
   */
  public void buildNewTree(InputStream stream) throws IOException {
    Scanner scan = new Scanner(stream, "UTF-8");
    // creating a new tree
    this.root = new TextNode();
    while (scan.hasNextLine()) {
      String s = scan.nextLine().trim();

      if (s.endsWith("=")) {
        s = s.substring(0, s.length() - 1);
        s = s.trim();
      }
      addWord(s);
    }
    scan.close();
  }
View Full Code Here

  private static String readFile(Resource resource) {

    try {

      Scanner scanner = new Scanner(resource.getInputStream());
      StringBuilder builder = new StringBuilder();

      while (scanner.hasNextLine()) {
        builder.append(scanner.nextLine()).append("\n");
      }

      scanner.close();

      return builder.toString();

    } catch (IOException o_O) {
      throw new RuntimeException(o_O);
View Full Code Here

        int rows = 0;
        int cols = -1;
        for (String line = null; (line = br.readLine()) != null; rows++) {
            // Create a scanner to parse out the values from the current line of
            // the file.
            Scanner s = new Scanner(line);
            s.useLocale(Locale.US);
            int vals = 0;
            // Count how many columns the row has
            for (; s.hasNextDouble(); vals++, s.nextDouble())
                ;

            // Base case if the number of columns has not been set
            if (cols == -1)
                cols = vals;
            // Otherwise, ensure that the number of values in the current row
            // matches the number of values seen in the first
            else {
                if (cols != vals) {
                    throw new MatrixIOException("line " + (rows + 1) +
                        " contains an inconsistent number of columns. " +
                        cols + " columns expected versus " + vals + " found.");
                }
            }
        }
        br.close();

        if (MATRIX_IO_LOGGER.isLoggable(Level.FINE)) {
            MATRIX_IO_LOGGER.fine("reading in text matrix with " + rows  +
                                  " rows and " + cols + " cols");
        }

        // Once the matrix has had its dimensions determined, re-open the file
        // to load the data into a Matrix instance.  Use a Scanner to parse the
        // text for us.
        Scanner scanner = new Scanner(matrix);
        scanner.useLocale(Locale.US);
        Matrix m = (transposeOnRead)
            ? Matrices.create(cols, rows, matrixType)
            : Matrices.create(rows, cols, matrixType);
       
        for (int row = 0; row < rows; ++row) {
            for (int col = 0; col < cols; ++col) {
                double d = scanner.nextDouble();
                if (transposeOnRead)
                    m.set(col, row, d);
                else
                    m.set(row, col, d);
            }
        }
        scanner.close();
       
        return m;
    }
View Full Code Here

    tokenRequest.addHeader("Authorization", AuthorizationCodeTestIT.authorizationBasic(clientId, secret));
    tokenRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpResponse tokenHttpResponse = new DefaultHttpClient().execute(tokenRequest);
    final InputStream responseContent = tokenHttpResponse.getEntity().getContent();
    String responseAsString = new Scanner(responseContent).useDelimiter("\\A").next();
    responseContent.close();
    tokenResponse = responseAsString;
  }
View Full Code Here

    File versionID = new File(path + File.separatorChar + ".VersionID");
    String versionString = "Unknown";

    try {
      if (versionID.exists()) {
        Scanner scanner = new Scanner(versionID).useDelimiter("\\A");
        if (scanner.hasNext()) versionString = scanner.next().trim();
      }
    } catch (FileNotFoundException ignored) {
    }
    return versionString;
  }
View Full Code Here

    // get possible appmaster error from stderr file
    StringBuilder masterFailReason = new StringBuilder();
    for (Resource res : resources) {
      File file = res.getFile();
      if (file.getName().endsWith("Appmaster.stderr") && file.length() > 0) {
        Scanner scanner = new Scanner(file);
        masterFailReason.append("[Appmaster.stderr=");
        masterFailReason.append(scanner.useDelimiter("\\A").next());
        masterFailReason.append("]");
        scanner.close();
        break;
      }
    }

    masterFailReason.append(", [ApplicationReport Diagnostics=");
    masterFailReason.append(client.getApplicationReport(applicationId).getDiagnostics());
    masterFailReason.append("], [Num of log files=");
    masterFailReason.append(resources.length);
    masterFailReason.append("]");

    assertThat(masterFailReason.toString(), state, is(YarnApplicationState.FINISHED));

    // appmaster and 4 containers should
    // make it 10 log files
    assertThat(resources, notNullValue());
    assertThat(resources.length, is(10));

    for (Resource res : resources) {
      File file = res.getFile();
      if (file.getName().endsWith("stdout")) {
        assertThat(file.length(), greaterThan(0l));
      } else if (file.getName().endsWith("stderr")) {
        String content = "";
        if (file.length() > 0) {
          Scanner scanner = new Scanner(file);
          content = scanner.useDelimiter("\\A").next();
          scanner.close();
        }
        if (content.contains("Unable to load realm info from SCDynamicStore")) {
          // due to OS X giving 'Unable to load realm info from SCDynamicStore' errors we allow 100 bytes here
          assertThat(file.length(), lessThan(100l));
        } else {
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.