Package java.util

Examples of java.util.Scanner


    final AbstractApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

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

    LOGGER.info(HORIZONTAL_LINE
          + "\n"
          + "\n    Please press 'q + Enter' to quit the application.    "
          + "\n"
          + HORIZONTAL_LINE );

    while (true) {

      final String input = scanner.nextLine();

      if("q".equals(input.trim())) {
        break;
      }

View Full Code Here


    public static Expression tokenizeExpression(final Expression expression,
                                                final String token) {
        return new ExpressionAdapter() {
            public Object evaluate(Exchange exchange) {
                Object value = expression.evaluate(exchange, Object.class);
                Scanner scanner = ObjectHelper.getScanner(exchange, value);
                scanner.useDelimiter(token);
                return scanner;
            }

            @Override
            public String toString() {
View Full Code Here

                                                     final String regexTokenizer) {
        final Pattern pattern = Pattern.compile(regexTokenizer);
        return new ExpressionAdapter() {
            public Object evaluate(Exchange exchange) {
                Object value = expression.evaluate(exchange, Object.class);
                Scanner scanner = ObjectHelper.getScanner(exchange, value);
                scanner.useDelimiter(pattern);
                return scanner;
            }

            @Override
            public String toString() {
View Full Code Here

    final AbstractApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

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


    final PersonService personService = context.getBean(PersonService.class);

    LOGGER.info("\n========================================================="
          + "\n                                                         "
          + "\n    Please press 'q + Enter' to quit the application.    "
          + "\n                                                         "
          + "\n=========================================================" );

    System.out.println("Please enter a choice and press <enter>: ");
    System.out.println("\t1. Find person details");
    System.out.println("\t2. Create a new person detail");
    System.out.println("\tq. Quit the application");
    System.out.print("Enter you choice: ");
    while (true) {
      final String input = scanner.nextLine();
      if("1".equals(input.trim())) {
        getPersonDetails(scanner, personService);
      } else if("2".equals(input.trim())) {
        createPersonDetails(scanner,personService);
      } else if("q".equals(input.trim())) {
View Full Code Here

            // this code is optimized to only use a Scanner if needed, eg there is a delimiter

            if (delimiter != null && s.contains(delimiter)) {
                // use a scanner if it contains the delimiter
                Scanner scanner = new Scanner((String)value);

                if (DEFAULT_DELIMITER.equals(delimiter)) {
                    // we use the default delimiter which is a comma, then cater for bean expressions with OGNL
                    // which may have balanced parentheses pairs as well.
                    // if the value contains parentheses we need to balance those, to avoid iterating
                    // in the middle of parentheses pair, so use this regular expression (a bit hard to read)
                    // the regexp will split by comma, but honor parentheses pair that may include commas
                    // as well, eg if value = "bean=foo?method=killer(a,b),bean=bar?method=great(a,b)"
                    // then the regexp will split that into two:
                    // -> bean=foo?method=killer(a,b)
                    // -> bean=bar?method=great(a,b)
                    // http://stackoverflow.com/questions/1516090/splitting-a-title-into-separate-parts
                    delimiter = ",(?!(?:[^\\(,]|[^\\)],[^\\)])+\\))";
                }

                scanner.useDelimiter(delimiter);
                return CastUtils.cast(scanner);
            } else {
                // use a plain iterator that returns the value as is as there are only a single value
                return new Iterator<Object>() {
                    private int idx;
View Full Code Here

            return getScanner(exchange, gf.getFile());
        }

        String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);

        Scanner scanner = null;
        if (value instanceof Readable) {
            scanner = new Scanner((Readable)value);
        } else if (value instanceof InputStream) {
            scanner = charset == null ? new Scanner((InputStream)value) : new Scanner((InputStream)value, charset);
        } else if (value instanceof File) {
            try {
                scanner = charset == null ? new Scanner((File)value) : new Scanner((File)value, charset);
            } catch (FileNotFoundException e) {
                throw new RuntimeCamelException(e);
            }
        } else if (value instanceof String) {
            scanner = new Scanner((String)value);
        } else if (value instanceof ReadableByteChannel) {
            scanner = charset == null ? new Scanner((ReadableByteChannel)value) : new Scanner((ReadableByteChannel)value, charset);
        }

        if (scanner == null) {
            // value is not a suitable type, try to convert value to a string
            String text = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
            if (text != null) {
                scanner = new Scanner(text);
            }
        }

        if (scanner == null) {
            scanner = new Scanner("");
        }

        return scanner;
    }
View Full Code Here

    @Override
    public void close() throws IOException {
        try {
            if (it instanceof Scanner) {
                // special for Scanner which implement the Closeable since JDK7
                Scanner scanner = (Scanner) it;
                scanner.close();
                IOException ioException = scanner.ioException();
                if (ioException != null) {
                    throw ioException;
                }
            } else if (it instanceof Closeable) {
                IOHelper.closeWithException((Closeable) it);
View Full Code Here

  }

  private static boolean containsLine(final String fileName,
      final String lineStop) {
    try {
      final Scanner s = new Scanner(System.in);

      final File f = new File(fileName);
      final Scanner numScan = new Scanner(f);

      String line;

      while (numScan.hasNext()) {
        line = numScan.nextLine();
        if (line.contains(lineStop)) {

          s.close();
          numScan.close();
          return true;
        }
      }
      s.close();
      numScan.close();
      return false;
    } catch (final FileNotFoundException e) {
      return true;
    }
  }
View Full Code Here

        super.tearDown();
    }

    public void testGroupIterator() throws Exception {
        String s = "ABC\nDEF\nGHI\nJKL\nMNO\nPQR\nSTU\nVW";
        Scanner scanner = new Scanner(s);
        scanner.useDelimiter("\n");

        GroupIterator gi = new GroupIterator(exchange, scanner, "\n", 3);

        assertTrue(gi.hasNext());
        assertEquals("ABC\nDEF\nGHI", gi.next());
View Full Code Here

        byte[] buf = "\u00A31\n\u00A32\n".getBytes(StandardCharsets.UTF_8);

        ByteArrayInputStream in = new ByteArrayInputStream(buf);

        Scanner scanner = new Scanner(in, StandardCharsets.UTF_8.displayName());
        scanner.useDelimiter("\n");

        exchange.setProperty(Exchange.CHARSET_NAME, StandardCharsets.UTF_8.displayName());
        GroupIterator gi = new GroupIterator(exchange, scanner, "\n", 1);

        assertTrue(gi.hasNext());
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.