List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:BlockingQueueTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk1.6.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); final int FILE_QUEUE_SIZE = 10; final int SEARCH_THREADS = 100; BlockingQueue<File> queue = new ArrayBlockingQueue<File>(FILE_QUEUE_SIZE); FileEnumerationTask enumerator = new FileEnumerationTask(queue, new File(directory)); new Thread(enumerator).start(); for (int i = 1; i <= SEARCH_THREADS; i++) new Thread(new SearchTask(queue, keyword)).start(); }
From source file:isc_415_practica_1.ISC_415_Practica_1.java
/** * @param args the command line arguments *///ww w . java 2 s .c o m public static void main(String[] args) { String urlString; Scanner input = new Scanner(System.in); Document doc; try { urlString = input.next(); if (urlString.equals("servlet")) { urlString = "http://localhost:8084/ISC_415_Practica1_Servlet/client"; } urlString = urlString.contains("http://") || urlString.contains("https://") ? urlString : "http://" + urlString; doc = Jsoup.connect(urlString).get(); } catch (Exception ex) { System.out.println("El URL ingresado no es valido."); return; } ArrayList<NameValuePair> formInputParams; formInputParams = new ArrayList<>(); String[] plainTextDoc = new TextNode(doc.html(), "").getWholeText().split("\n"); System.out.println(String.format("Nmero de lineas del documento: %d", plainTextDoc.length)); System.out.println(String.format("Nmero de p tags: %d", doc.select("p").size())); System.out.println(String.format("Nmero de img tags: %d", doc.select("img").size())); System.out.println(String.format("Nmero de form tags: %d", doc.select("form").size())); Integer index = 1; ArrayList<NameValuePair> urlParameters = new ArrayList<>(); for (Element e : doc.select("form")) { System.out.println(String.format("Form %d: Nmero de Input tags %d", index, e.select("input").size())); System.out.println(e.select("input")); for (Element formInput : e.select("input")) { if (formInput.attr("id") != null && formInput.attr("id") != "") { urlParameters.add(new BasicNameValuePair(formInput.attr("id"), "PRACTICA1")); } else if (formInput.attr("name") != null && formInput.attr("name") != "") { urlParameters.add(new BasicNameValuePair(formInput.attr("name"), "PRACTICA1")); } } index++; } if (!urlParameters.isEmpty()) { try { CloseableHttpClient httpclient = HttpClients.createDefault(); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, Consts.UTF_8); HttpPost httpPost = new HttpPost(urlString); httpPost.setHeader("User-Agent", USER_AGENT); httpPost.setEntity(entity); HttpResponse response = httpclient.execute(httpPost); System.out.println(response.getStatusLine()); } catch (IOException ex) { Logger.getLogger(ISC_415_Practica_1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:br.upf.contatos.tcp.Client.java
public static void main(String[] args) throws RuntimeException { String teste = Arrays.toString(args); if (args.length == 0) { Client.HOST = "localhost"; } else {/*w w w. j a v a 2s . c o m*/ Client.HOST = args[0]; } ClientConnector tcpService = new ClientConnector(Client.HOST, PORTA); String line; tcpService.connect(); do { System.out.println("Digite help, para o menu"); Scanner scanner = new Scanner(System.in); line = scanner.nextLine(); } while (comando(line, tcpService)); tcpService.disconnect(); }
From source file:fi.jyu.it.ties456.week38.Main.Main.java
public static void main(String[] args) throws NoSuchTeacherException_Exception { TeacherRegistryService connect = new TeacherRegistryService(); TeacherRegistry teacher = connect.getTeacherRegistryPort(); CourseISService connectCourse = new CourseISService(); CourseIS course = connectCourse.getCourseISPort(); int i;/*from ww w. j av a 2 s. c o m*/ Scanner inputchoice = new Scanner(System.in); Scanner cin = new Scanner(System.in); do { System.out.println("0: Quit the application"); System.out.println("1: Search the teacher Info"); System.out.println("2: Create the Course"); i = inputchoice.nextInt(); switch (i) { case 0: System.out.println("quit the application"); break; case 1: System.out.println("Input search info of teacher"); String searchString = cin.nextLine(); JSONObject result = searchTeacher(teacher, searchString); if (result == null) System.out.println("No person found"); else System.out.println(result); break; case 2: createCourse(teacher, course); break; default: System.err.println("Not a valid choice"); } } while (i != 0); }
From source file:Clima.Clima.java
public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner lea = new Scanner(System.in); int op;//from w ww . ja v a2s .c o m do { System.out.println("----------\nMENU\n-----------"); System.out.println("1- Ver todos los datos clima"); System.out.println("2- Ver longuitud y Latitud"); System.out.println("3- Temperatura minima y maxima"); System.out.println("4- Humedad y Velocidad"); System.out.println("Escoja Opcion: "); op = lea.nextInt(); System.out.println("------------------------------------"); System.out.println("Ingrase la ciudad que decea ver clima"); System.out.println("-------------------------------------"); String cuida = lea.next(); System.out.println("--------------------------------------"); switch (op) { case 1: try { String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55"); JSONObject obj = new JSONObject(respuesta); double temp = obj.getJSONObject("main").getDouble("temp") - 273.15; double lon = obj.getJSONObject("coord").getDouble("lon"); double lat = obj.getJSONObject("coord").getDouble("lat"); double pressure = obj.getJSONObject("main").getDouble("pressure"); double humidity = obj.getJSONObject("main").getDouble("humidity"); double temp_min = obj.getJSONObject("main").getDouble("temp_min") - 273.15; double temp_max = obj.getJSONObject("main").getDouble("temp_max") - 273.15; double speed = obj.getJSONObject("wind").getDouble("speed"); System.out.println("Los datos optenidos de " + cuida); System.out.println("***************************************1"); System.out.println("La temperatura es: " + temp + " Celsius"); System.out.println("longuitud es: " + lon); System.out.println("Latitud es: " + lat); System.out.println("La presurisacion es: " + pressure); System.out.println("La humedad es: " + humidity); System.out.println("La temperatura minima es: " + temp_min + " Celsius"); System.out.println("La temperatura maxima es: " + temp_max + " Celsius"); System.out.println("La velocidad es: " + speed); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Clima.main(null); break; case 2: try { String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55"); JSONObject obj = new JSONObject(respuesta); double lon = obj.getJSONObject("coord").getDouble("lon"); double lat = obj.getJSONObject("coord").getDouble("lat"); System.out.println("Los datos optenidos de" + cuida + "son:"); System.out.print("longuitud es: " + lon); System.out.print("Latitud es: " + lat); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Clima.main(null); break; case 3: try { String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55"); JSONObject obj = new JSONObject(respuesta); double temp_min = obj.getJSONObject("main").getDouble("temp_min") - 273.15; double temp_max = obj.getJSONObject("main").getDouble("temp_max") - 273.15; System.out.println("Los datos optenidos de" + cuida + "son:"); System.out.print("La temperatura minima es: " + temp_min + " Celsius"); System.out.print("La temperatura maxima es: " + temp_max + " Celsius"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Clima.main(null); break; case 4: try { String respuesta = getHTML("http://api.openweathermap.org/data/2.5/weather?q=" + cuida + ",uk&appid=edf6a6fe68ae2a1259efacb437914a55"); JSONObject obj = new JSONObject(respuesta); double humidity = obj.getJSONObject("main").getDouble("humidity"); double speed = obj.getJSONObject("wind").getDouble("speed"); System.out.println("Los datos optenidos de" + cuida + "son:"); System.out.print("La humedad es: " + humidity); System.out.print("La velocidad es: " + speed); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Clima.main(null); break; } } while (op != 8); }
From source file:FutureTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); MatchCounter counter = new MatchCounter(new File(directory), keyword); FutureTask<Integer> task = new FutureTask<Integer>(counter); Thread t = new Thread(task); t.start();//from ww w .j ava 2 s. co m try { System.out.println(task.get() + " matching files."); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { } }
From source file:RegExTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter pattern: "); String patternString = in.nextLine(); Pattern pattern = null;/* w ww . j av a2 s. co m*/ try { pattern = Pattern.compile(patternString); } catch (PatternSyntaxException e) { System.out.println("Pattern syntax error"); System.exit(1); } while (true) { System.out.println("Enter string to match: "); String input = in.nextLine(); if (input == null || input.equals("")) return; Matcher matcher = pattern.matcher(input); if (matcher.matches()) { System.out.println("Match"); int g = matcher.groupCount(); if (g > 0) { for (int i = 0; i < input.length(); i++) { for (int j = 1; j <= g; j++) if (i == matcher.start(j)) System.out.print('('); System.out.print(input.charAt(i)); for (int j = 1; j <= g; j++) if (i + 1 == matcher.end(j)) System.out.print(')'); } System.out.println(); } } else System.out.println("No match"); } }
From source file:SocketTest.java
public static void main(String[] args) { try {/*w w w . j a v a2 s .c om*/ Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13); try { InputStream inStream = s.getInputStream(); Scanner in = new Scanner(inStream); while (in.hasNextLine()) { String line = in.nextLine(); System.out.println(line); } } finally { s.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:ThreadPoolTest.java
public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); ExecutorService pool = Executors.newCachedThreadPool(); MatchCounter counter = new MatchCounter(new File(directory), keyword, pool); Future<Integer> result = pool.submit(counter); try {/* w w w . j a v a2 s . co m*/ System.out.println(result.get() + " matching files."); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { } pool.shutdown(); int largestPoolSize = ((ThreadPoolExecutor) pool).getLargestPoolSize(); System.out.println("largest pool size=" + largestPoolSize); }
From source file:io.github.mikesaelim.arxivoaiharvester.CommandLineInterface.java
public static void main(String[] args) throws InterruptedException { CloseableHttpClient httpClient = HttpClients.createDefault(); ArxivOAIHarvester harvester = new ArxivOAIHarvester(httpClient); Scanner scanner = new Scanner(System.in); System.out.println();/*ww w.j a v a 2s .co m*/ System.out.println("Welcome to the command line interface of the arXiv OAI Harvester!"); System.out.println( "This program sends one query to the arXiv OAI repository and prints the results to STDOUT."); System.out.println("It uses the default settings for query retries."); System.out.println(); System.out.println("Which verb would you like to use?"); System.out.println(" 1) GetRecord - retrieve a single record"); System.out.println(" 2) ListRecords - retrieve a range of records"); System.out.println(" or enter anything else to quit."); switch (scanner.nextLine().trim()) { case "1": handleGetRecordRequest(scanner, harvester); break; case "2": handleListRecordsRequest(scanner, harvester); } }