List of usage examples for java.util Scanner next
public String next()
From source file:com.asuraiv.coordination.menu.MainMenu.java
@Override public void displayMenu() { boolean isContinue = true; while (isContinue) { System.out.println();//from w ww.ja va2 s. co m System.out.println(); System.out.println("### Main MENU ###"); System.out.println("1. ?"); System.out.println("2. "); System.out.println("3. "); System.out.println("99. "); System.out.println(); System.out.print(" ? > "); @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); switch (scanner.next()) { case "1": nextMenu = new RegistTaskMenu(); isContinue = false; break; case "2": doTaskListUp(); isContinue = true; break; case "3": doDeleteTasks(); isContinue = true; break; case "99": // isContinue = false; break; default: System.out.println("[WRONG!] ."); isContinue = true; break; } } nextMenu.displayMenu(); }
From source file:com.mirth.connect.client.ui.components.rsta.ac.js.PartialHashMap.java
private String[] splitKey(String key) { List<String> list = new ArrayList<String>(); Scanner scanner = new Scanner(key); scanner.useDelimiter(SPLIT_PATTERN); while (scanner.hasNext()) { list.add(scanner.next().toLowerCase()); }/*w ww . ja v a 2s . c o m*/ scanner.close(); return list.toArray(new String[list.size()]); }
From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java
/** * Checks whether files extension is allowed. * * @param fileExt a string representing file extension to test * @param type a {@code ResourceType} object holding list of allowed and denied extensions against which parameter fileExt will be * tested/*w w w .j a v a2 s . com*/ * @return {@code true} is extension is on allowed extensions list or if allowed extensions is empty. The {@code false} is returned when * file is on denied extensions list or if none of the above conditions is met. */ private static boolean checkSingleExtension(final String fileExt, final ResourceType type) { Scanner scanner = new Scanner(type.getDeniedExtensions()).useDelimiter(","); while (scanner.hasNext()) { if (scanner.next().equalsIgnoreCase(fileExt)) { return false; } } scanner = new Scanner(type.getAllowedExtensions()).useDelimiter(","); //The allowedExtensions is empty. Allow everything that isn't dissallowed. if (!scanner.hasNext()) { return true; } while (scanner.hasNext()) { if (scanner.next().equalsIgnoreCase(fileExt)) { return true; } } return false; }
From source file:org.trafodion.rest.util.NetworkConfiguration.java
public void checkCloud() { //Ideally we want to use http://jclouds.apache.org/ so we can support all cloud providers. //For now, use OpenStack Nova to retrieve int/ext network address map. LOG.info("Checking Cloud environment"); String cloudCommand = conf.get(Constants.REST_CLOUD_COMMAND, Constants.DEFAULT_REST_CLOUD_COMMAND); ScriptContext scriptContext = new ScriptContext(); scriptContext.setScriptName(Constants.SYS_SHELL_SCRIPT_NAME); scriptContext.setCommand(cloudCommand); LOG.info(scriptContext.getScriptName() + " exec [" + scriptContext.getCommand() + "]"); ScriptManager.getInstance().runScript(scriptContext);//This will block while script is running StringBuilder sb = new StringBuilder(); sb.append(scriptContext.getScriptName() + " exit code [" + scriptContext.getExitCode() + "]"); if (!scriptContext.getStdOut().toString().isEmpty()) sb.append(", stdout [" + scriptContext.getStdOut().toString() + "]"); if (!scriptContext.getStdErr().toString().isEmpty()) sb.append(", stderr [" + scriptContext.getStdErr().toString() + "]"); LOG.info(sb.toString());/*from ww w . j av a2 s . c o m*/ if (!scriptContext.getStdOut().toString().isEmpty()) { Scanner scn = new Scanner(scriptContext.getStdOut().toString()); scn.useDelimiter(","); intHostAddress = scn.next();//internal ip extHostAddress = scn.next();//external ip scn.close(); LOG.info("Cloud environment found"); } else LOG.info("Cloud environment not found"); }
From source file:org.apache.streams.datasift.example.DatasiftWebhookResource.java
@POST @Path("json_new_line") public Response datasift_json_new_line(@Context HttpHeaders headers, String body) { //log.debug(headers.toString(), headers); //log.debug(body.toString(), body); ObjectNode response = mapper.createObjectNode(); if (body.equalsIgnoreCase("{}")) { Boolean success = true;/*from w ww .jav a2 s . c o m*/ response.put("success", success); return Response.status(200).entity(response).build(); } try { Scanner scanner = new Scanner(body); while (scanner.hasNext()) { String item = scanner.next(); StreamsDatum datum = new StreamsDatum(item); lock.writeLock().lock(); ComponentUtils.offerUntilSuccess(datum, providerQueue); lock.writeLock().unlock(); } log.info("interactionQueue: " + providerQueue.size()); Boolean success = true; response.put("success", success); return Response.status(200).entity(response).build(); } catch (Exception e) { log.warn(e.toString(), e); } return Response.status(500).build(); }
From source file:org.neo4j.server.web.logging.HTTPLoggingFunctionalTest.java
private boolean occursIn(String lookFor, File file) throws FileNotFoundException { if (!file.exists()) { return false; }//from ww w .j av a 2 s .c o m boolean result = false; Scanner scanner = new Scanner(file); while (scanner.hasNext()) { if (scanner.next().contains(lookFor)) { result = true; } } scanner.close(); return result; }
From source file:org.terracotta.management.registry.ManagementRegistryTest.java
@Test public void test_management_registry_exposes() throws IOException { ManagementRegistry registry = new AbstractManagementRegistry() { @Override/* w w w . j a v a 2 s . co m*/ public ContextContainer getContextContainer() { return new ContextContainer("cacheManagerName", "my-cm-name"); } }; registry.addManagementProvider(new MyManagementProvider()); registry.register(new MyObject("myCacheManagerName", "myCacheName1")); registry.register(new MyObject("myCacheManagerName", "myCacheName2")); Scanner scanner = new Scanner(ManagementRegistryTest.class.getResourceAsStream("/capabilities.json"), "UTF-8").useDelimiter("\\A"); String expectedJson = scanner.next(); scanner.close(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.addMixIn(CapabilityContext.class, CapabilityContextMixin.class); String actual = mapper.writeValueAsString(registry.getCapabilities()); System.out.println(expectedJson); System.out.println(actual); assertEquals(expectedJson, actual); ContextualReturn<?> cr = registry.withCapability("TheActionProvider") .call("incr", int.class, new Parameter(Integer.MAX_VALUE, "int")).on(Context.empty() .with("cacheManagerName", "myCacheManagerName").with("cacheName", "myCacheName1")) .build().execute().getSingleResult(); try { cr.getValue(); fail(); } catch (ExecutionException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); } }
From source file:org.activiti.engine.impl.bpmn.helper.NGSISubscribeContextClient.java
private void readHTTPResponse() throws IllegalStateException, IOException, XmlException { InputStream input = httpresponse.getEntity().getContent(); java.util.Scanner s = new java.util.Scanner(input).useDelimiter("\\A"); String string = s.hasNext() ? s.next() : ""; System.out.println("NGSI response:\n" + string); SubscribeContextResponseDocument responseDoc = SubscribeContextResponseDocument.Factory.parse(string); subscribeContextResponse = responseDoc.getSubscribeContextResponse(); if (!subscribeContextResponse.validate()) throw new ActivitiException("Response from NGSI server is not valid"); }
From source file:org.whispersystems.bithub.tests.controllers.GithubControllerTest.java
protected String payload(String path) { InputStream is = this.getClass().getResourceAsStream(path); Scanner s = new Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:com.loopj.android.http.sample.CustomCASample.java
/** * Returns contents of `custom_ca.txt` file from assets as CharSequence. * * @return contents of custom_ca.txt file *//*from w ww . j av a 2 s . c o m*/ private CharSequence getReadmeText() { String rtn = ""; try { InputStream stream = getResources().openRawResource(R.raw.custom_ca); java.util.Scanner s = new java.util.Scanner(stream).useDelimiter("\\A"); rtn = s.hasNext() ? s.next() : ""; } catch (Resources.NotFoundException e) { Log.e(LOG_TAG, "License couldn't be retrieved", e); } return rtn; }