Package java.util

Examples of java.util.Scanner


   * @return A DefaultTableModel containing the CSV values as type String
   */
  public static DefaultTableModel createTableModel(final Reader in,
      Vector<Object> headers) {
    DefaultTableModel model = null;
    Scanner s = null;

    try {
      try {
        final Vector<Vector<Object>> rows = new Vector<Vector<Object>>();
        s = new Scanner(in);
        if (!s.hasNext()) {
          return null;
        }

        while (s.hasNextLine()) {
          rows.add(new Vector<Object>(Arrays.asList(s.nextLine()
              .split("(?<!\\\\),", -1))));

        }

        if (headers == null) {
          headers = rows.remove(0);

          model = new DefaultTableModel(rows, headers) {

            /**
             *
             */
            private static final long serialVersionUID = -611084662140321390L;

            @Override
            public boolean isCellEditable(final int row,
                final int column) {

              return false;
            }
          };
        } else {

          model = new DefaultTableModel(rows, headers) {

            /**
             *
             */
            private static final long serialVersionUID = -1929719310445045512L;

            @Override
            public boolean isCellEditable(final int row,
                final int column) {

              return false;
            }
          };
        }

        return model;
      } catch (final Exception e) {
        return null;
      }

    } finally {

      s.close();
    }
  }
View Full Code Here


  public static void sed(InputStream inputStream, OutputStream outputStream, Map<Pattern, String> patternReplacements) throws IOException {
    if(patternReplacements == null || patternReplacements.isEmpty()) {
      return;
    }

    Scanner scanner = new Scanner(inputStream).useDelimiter(Pattern.compile("\n"));
    while(scanner.hasNext()) {
      String line = scanner.next();
      String next = null;
      for (Map.Entry<Pattern, String> patternReplacement : patternReplacements.entrySet()) {
        Matcher matcher;
        if(next == null) {
          matcher = patternReplacement.getKey().matcher(line);
View Full Code Here

   *
   * @param args - command line arguments
   */
  public static void main(final String... args) {

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

    LOGGER.info("\n========================================================="
          + "\n                                                         "
          + "\n          Welcome to Spring Integration's                "
          + "\n     Stored Procedure/Function Sample for Oracle         "
          + "\n                                                         "
          + "\n    For more information please visit:                   "
          + "\n    http://www.springsource.org/spring-integration       "
          + "\n                                                         "
          + "\n=========================================================" );

    while (true) {

      System.out.println("Please enter a choice and press <enter>: ");
      System.out.println("\t1. Execute Sample 1 (Capitalize String)");
      System.out.println("\t2. Execute Sample 2 (Coffee Service)");
      System.out.println("\tq. Quit the application");

      final String input = scanner.nextLine();

      if("1".equals(input.trim())) {
        executeSample1();
        continue;
      } else if("2".equals(input.trim())) {
View Full Code Here

  }

  private static void executeSample1() {

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

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:META-INF/spring/integration/spring-integration-sample1-context.xml");
    context.registerShutdownHook();
    context.refresh();

    final StringConversionService service = context.getBean(StringConversionService.class);

    final String message =
          "\n========================================================="
        + "\n                                                         "
        + "\n    Please press 'q + Enter' to quit the application.    "
        + "\n                                                         "
        + "\n========================================================="
        + "\n\n Please enter a string and press <enter>: ";

    System.out.print(message);

    while (!scanner.hasNext("q")) {
      String input = scanner.nextLine();

      System.out.println("Converting String to Uppcase using Stored Procedure...");
      String inputUpperCase = service.convertToUpperCase(input);

      System.out.println("Retrieving Numeric value via Sql Function...");
View Full Code Here

  }

  private static void executeSample2() {

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

    final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load("classpath:META-INF/spring/integration/spring-integration-sample2-context.xml");
    context.registerShutdownHook();
    context.refresh();

    final CoffeeService service = context.getBean(CoffeeService.class);

    final String message = "\n\n" +
      "* Please enter 'list' and press <enter> to get a list of coffees.\n" +
      "* Enter a coffee id, e.g. '1' and press <enter> to get a description.\n" +
      "* Please press 'q + Enter' to quit the application.\n";

    System.out.println(message);

    while (!scanner.hasNext("q")) {

      String input = scanner.nextLine();

      if ("list".equalsIgnoreCase(input)) {
        List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();

        for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
View Full Code Here

    "/META-INF/spring/integration/outboundChannelAdapter.xml"
  };

  public static void main(String[] args) {

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

    System.out.println("\n========================================================="
        + "\n                                                         "
        + "\n    Welcome to the Spring Integration JMS Sample!        "
        + "\n                                                         "
        + "\n    For more information please visit:                   "
        + "\n    http://www.springintegration.org/                    "
        + "\n                                                         "
        + "\n=========================================================" );

    ActiveMqTestUtils.prepare();

    System.out.println("\n    Which Demo would you like to run? <enter>:\n");
    System.out.println("\t1. Channel Adapter Demo");
    System.out.println("\t2. Gateway Demo");

    while (true) {
      final String input = scanner.nextLine();

      if("1".equals(input.trim())) {
        System.out.println("    Loading Channel Adapter Demo...");
        new ClassPathXmlApplicationContext(configFilesChannelAdapterDemo, Main.class);
        break;
View Full Code Here

    public ConnectionSettings(final String host, final int port, final String tube) {
        this.host = host;
        this.port = port;

        final Scanner scanner = new Scanner(tube);
        scanner.useDelimiter("\\+");
        final ArrayList<String> buffer = new ArrayList<String>();
        while (scanner.hasNext()) {
            final String tubeRaw = scanner.next();
            try {
                buffer.add(URLDecoder.decode(tubeRaw, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                buffer.add(tubeRaw);
            }
        }
        this.tubes = buffer.toArray(new String[buffer.size()]);
        scanner.close();
    }
View Full Code Here

    public void setPeriod(String period) {
        notNull(period, "period");
        int result = 0;
        try {
            result = new Scanner(period).useDelimiter("\\D+").nextInt();
        } catch (Exception e) {
            // ignore and fallback the period to be an empty string
        }
        if (result != 0) {
            this.period = "" + result;
View Full Code Here

        private Scanner scanner;

        KatScanner(String fileName) {
            try {
                scanner = new Scanner(new File(fileName));
                scanner.useDelimiter(System.getProperty("line.separator"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
View Full Code Here

        void parseMessageLine(String line, KatResult kr) {
            if (line.contains("(none)")) {
                kr.msg[kr.msgFill++] = 0;
                return;
            }
            Scanner ls = new Scanner(line);
            while (ls.hasNext()) {
                try {
                    kr.msg[kr.msgFill++] = (byte) ls.nextInt(16);
                } catch (Exception e) {
                    System.out.println("Msg data: " + line);
                    e.printStackTrace();
                    System.exit(1);
                }
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.