List of usage examples for java.lang String trim
public String trim()
From source file:com.hsbc.srbp.commonMsg.test.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w.j a va2s. co m */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "jdbcInboundApplicationContext.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final CommonMessageService commonMessageService = context.getBean(CommonMessageService.class); System.out.println("\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. Create a new message 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())) { createMessageDetails(scanner, commonMessageService, context); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } System.out.println("Exiting application...."); System.exit(0); }
From source file:com.lv.tica.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w. j ava2s. c o m */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration!!! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:com.richard.memorystore.udp.UDPServer.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/* w ww . jav a 2s . c o m*/ */ public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration " + "\n TCP-Client-Server Sample! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n========================================================="); final GenericXmlApplicationContext context = UDPServer.setupContext(); // final SimpleGateway gateway = context.getBean(SimpleGateway.class); // final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class); System.out.print("Waiting for server to accept connections..."); //TestingUtilities.waitListening(crLfServer, 10000L); System.out.println("running.\n\n"); System.out.println("Please enter some text and press <enter>: "); System.out.println("\tNote:"); System.out.println("\t- Entering FAIL will create an exception"); System.out.println("\t- Entering q will quit the application"); System.out.print("\n"); System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests."); //System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n"); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } // else { // final String result = gateway.send(input); // System.out.println(result); // } } System.out.println("Exiting application...bye."); System.exit(0); }
From source file:in.datashow.zla.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/* www . j a va2s . co m*/ */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:UseTrim.java
public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; System.out.println("Enter 'stop' to quit."); System.out.println("Enter letter: "); do {//from ww w . j av a 2s. c o m str = br.readLine(); str = str.trim(); if (str.equals("I")) System.out.println("I"); else if (str.equals("M")) System.out.println("M"); else if (str.equals("C")) System.out.println("C."); else if (str.equals("W")) System.out.println("W"); } while (!str.equals("stop")); }
From source file:com.cjtotten.example.si.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from ww w.j av a2 s. c om*/ */ public static void main(final String... args) { if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); } final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final StringConversionService service = context.getBean(StringConversionService.class); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); } System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (Exception e) { LOGGER.error("An exception was caught: " + e); } System.out.print("Please enter a string and press <enter>:"); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } System.exit(0); }
From source file:org.apache.samza.sql.master.SamzaSQLMaster.java
public static void main(String[] args) throws Exception { Server jettyServer = createJettyServer(); try {// w ww. j a va 2s. c om jettyServer.start(); String mode = System.getProperty(PROP_MODE); if (mode != null && mode.trim().equals("dev")) { jettyServer.dump(System.err); } jettyServer.join(); } finally { jettyServer.destroy(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { Charset charset = Charset.forName("ISO-8859-1"); CharsetEncoder encoder = charset.newEncoder(); CharsetDecoder decoder = charset.newDecoder(); ByteBuffer buffer = ByteBuffer.allocate(512); Selector selector = Selector.open(); ServerSocketChannel server = ServerSocketChannel.open(); server.socket().bind(new java.net.InetSocketAddress(8000)); server.configureBlocking(false);//from ww w .ja v a 2s . co m SelectionKey serverkey = server.register(selector, SelectionKey.OP_ACCEPT); for (;;) { selector.select(); Set keys = selector.selectedKeys(); for (Iterator i = keys.iterator(); i.hasNext();) { SelectionKey key = (SelectionKey) i.next(); i.remove(); if (key == serverkey) { if (key.isAcceptable()) { SocketChannel client = server.accept(); client.configureBlocking(false); SelectionKey clientkey = client.register(selector, SelectionKey.OP_READ); clientkey.attach(new Integer(0)); } } else { SocketChannel client = (SocketChannel) key.channel(); if (!key.isReadable()) continue; int bytesread = client.read(buffer); if (bytesread == -1) { key.cancel(); client.close(); continue; } buffer.flip(); String request = decoder.decode(buffer).toString(); buffer.clear(); if (request.trim().equals("quit")) { client.write(encoder.encode(CharBuffer.wrap("Bye."))); key.cancel(); client.close(); } else { int num = ((Integer) key.attachment()).intValue(); String response = num + ": " + request.toUpperCase(); client.write(encoder.encode(CharBuffer.wrap(response))); key.attach(new Integer(num + 1)); } } } } }
From source file:com.haythem.integration.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/* www . j a v a 2 s . c o m*/ */ public static void main(final String... args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration " + "\n TCP-Client-Server Sample! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n========================================================="); final GenericXmlApplicationContext context = Main.setupContext(); final SimpleGateway gateway = context.getBean(SimpleGateway.class); final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class); System.out.print("Waiting for server to accept connections..."); TestingUtilities.waitListening(crLfServer, 10000L); System.out.println("running.\n\n"); System.out.println("Please enter some text and press <enter>: "); System.out.println("\tNote:"); System.out.println("\t- Entering FAIL will create an exception"); System.out.println("\t- Entering q will quit the application"); System.out.print("\n"); System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests."); System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n"); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } else { final String result = gateway.send(input); System.out.println(result); } } System.out.println("Exiting application...bye."); System.exit(0); }
From source file:com.seavus.wordcountermaven.WordCounter.java
/** * @param args the command line arguments * @throws java.io.FileNotFoundException *//* ww w. j a v a2 s .co m*/ public static void main(String[] args) throws FileNotFoundException { InputStream fileStream = WordCounter.class.getClassLoader().getResourceAsStream("test.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fileStream)); Map<String, Integer> wordMap = new HashMap<>(); String line; boolean tokenFound = false; try { while ((line = br.readLine()) != null) { String[] tokens = line.trim().split("\\s+"); //trims surrounding whitespaces and splits lines into tokens for (String token : tokens) { for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { if (StringUtils.equalsIgnoreCase(token, entry.getKey())) { wordMap.put(entry.getKey(), (wordMap.get(entry.getKey()) + 1)); tokenFound = true; } } if (!token.equals("") && !tokenFound) { wordMap.put(token.toLowerCase(), 1); } tokenFound = false; } } br.close(); } catch (IOException ex) { Logger.getLogger(WordCounter.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("string : " + "frequency\r\n" + "-------------------"); //prints out each unique word (i.e. case-insensitive string token) and its frequency to the console for (Map.Entry<String, Integer> entry : wordMap.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } }