List of usage examples for java.util Scanner hasNextLine
public boolean hasNextLine()
From source file:csns.test.Setup.java
/** * Spring's executeSqlScript() splits the script into statements and * executes each statement individually. The problem is that the split is * based on simple delimiters like semicolon and it does not recognize the * syntax of create function/procedure. So in order to run csns-create.sql, * we have to read the file into a string and pass the whole thing to the * JDBC driver.//w w w .j a v a 2 s .co m */ @SuppressWarnings("deprecation") private void executeSqlScript(String path) { try { StringBuilder sb = new StringBuilder(); Resource resource = applicationContext.getResource(path); Scanner in = new Scanner(resource.getFile()); while (in.hasNextLine()) { sb.append(in.nextLine()); sb.append("\n"); } in.close(); simpleJdbcTemplate.update(sb.toString()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.geode.management.internal.security.LogNoPasswordTest.java
@Test public void testPasswordInLogs() throws Exception { Properties properties = new Properties(); properties.setProperty(LOG_LEVEL, "debug"); properties.setProperty(SECURITY_MANAGER, MySecurityManager.class.getName()); MemberVM locator = lsRule.startLocatorVM(0, properties); gfsh.secureConnectAndVerify(locator.getHttpPort(), GfshShellConnectionRule.PortType.http, "any", PASSWORD); gfsh.executeAndVerifyCommand("list members"); // scan all locator log files to find any occurrences of password File[] serverLogFiles = locator.getWorkingDir().listFiles(file -> file.toString().endsWith(".log")); File[] gfshLogFiles = gfsh.getWorkingDir().listFiles(file -> file.toString().endsWith(".log")); File[] logFiles = (File[]) ArrayUtils.addAll(serverLogFiles, gfshLogFiles); for (File logFile : logFiles) { Scanner scanner = new Scanner(logFile); while (scanner.hasNextLine()) { String line = scanner.nextLine(); assertThat(line).describedAs("File: %s, Line: %s", logFile.getAbsolutePath(), line) .doesNotContain(PASSWORD); }/*from ww w.j av a 2 s.com*/ } }
From source file:eu.planets_project.services.datatypes.ContentTests.java
/** * @param source The source to read from * @return Returns the content of the source *//*w w w .ja va 2s. c om*/ private String read(final InputStream source) { StringBuilder builder = new StringBuilder(); Scanner s = new Scanner(source); while (s.hasNextLine()) { builder.append(s.nextLine()).append("\n"); } return builder.toString().trim(); }
From source file:com.threewks.thundr.configuration.PropertiesLoader.java
private Map<String, String> readProperties(String resourceAsString) { Map<String, String> properties = new LinkedHashMap<String, String>(); Scanner scanner = new Scanner(resourceAsString); try {/*from w w w. j a v a2 s . c o m*/ while (scanner.hasNextLine()) { String line = scanner.nextLine(); line = StringUtils.substringBefore(line, "#"); line = StringUtils.trimToNull(line); String key = StringUtils.substringBefore(line, "="); String value = StringUtils.substringAfter(line, "="); if (key != null) { properties.put(key, value); } } } finally { scanner.close(); } return properties; }
From source file:org.apache.oodt.cas.protocol.http.TestHttpProtocol.java
public void testGET() throws ProtocolException, IOException { HttpProtocol httpProtocol = new HttpProtocol(); httpProtocol.connect("svn.apache.org", new NoAuthentication()); assertTrue(httpProtocol.connected()); httpProtocol.cd(new ProtocolFile( "repos/asf/oodt/trunk/protocol/http/src/test/java/org/apache/oodt/cas" + "/protocol/http", true)); File bogus = File.createTempFile("bogus", "bogus"); File tmpDir = new File(bogus.getParentFile(), "TestHttpProtocol"); bogus.delete();// w ww . j a va2s .c om tmpDir.mkdirs(); File toFile = new File(tmpDir, "TestHttpProtocol.java"); httpProtocol.get(new ProtocolFile("TestHttpProtocol.java", false), toFile); assertTrue(toFile.exists()); assertNotSame(0, toFile.length()); String fileContent = ""; Scanner scanner = new Scanner(toFile); while (scanner.hasNextLine()) { fileContent += scanner.nextLine(); } assertEquals(fileContent, HttpUtils.readUrl(HttpUtils.connect( new URL("http://svn.apache.org/repos/asf/oodt/" + "trunk/protocol/http/src/test/java/org/" + "apache/oodt/cas/protocol/http/" + "TestHttpProtocol.java")))); FileUtils.forceDelete(tmpDir); }
From source file:org.apache.accumulo.shell.commands.ExecfileCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { Scanner scanner = new Scanner(new File(cl.getArgs()[0]), UTF_8.name()); try {//from www .j a v a2 s . com while (scanner.hasNextLine()) { shellState.execCommand(scanner.nextLine(), true, cl.hasOption(verboseOption.getOpt())); } } finally { scanner.close(); } return 0; }
From source file:net.praqma.clearcase.test.unit.LoadRules2Test.java
public List<String> mockConsoleOut(String filename) throws Exception { InputStream is;//from w w w . j a v a2 s . c om is = LoadRules2Test.class.getResourceAsStream(filename); List<String> lines = new ArrayList<String>(); try { Scanner scan = new Scanner(is); while (scan.hasNextLine()) { lines.add(scan.nextLine()); } } finally { is.close(); } return lines; }
From source file:org.apache.streams.console.ConsolePersistReader.java
@Override public StreamsResultSet readCurrent() { LOGGER.info("{} readCurrent", STREAMS_ID); Scanner sc = new Scanner(inputStream); while (sc.hasNextLine()) { persistQueue.offer(new StreamsDatum(sc.nextLine())); }/*from w ww .j av a2 s.com*/ LOGGER.info("Providing {} docs", persistQueue.size()); StreamsResultSet result = new StreamsResultSet(persistQueue); LOGGER.info("{} Exiting", STREAMS_ID); return result; }
From source file:org.apache.accumulo.core.util.shell.commands.ExecfileCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { Scanner scanner = new Scanner(new File(cl.getArgs()[0]), Constants.UTF8.name()); try {/* ww w . ja v a 2 s . co m*/ while (scanner.hasNextLine()) { shellState.execCommand(scanner.nextLine(), true, cl.hasOption(verboseOption.getOpt())); } } finally { scanner.close(); } return 0; }
From source file:org.fcrepo.modeshape.ModeshapeServer.java
private void start(boolean benchEnabled, int num, long size, int threads) throws Exception { RepositoryConfiguration cfg = RepositoryConfiguration .read(this.getClass().getClassLoader().getResourceAsStream("repository.json"), "repo"); ModeShapeEngine engine = new ModeShapeEngine(); engine.start();// w w w . j a v a 2s . c om Repository repo = engine.deploy(cfg); repo.login(); while (engine.getRepositoryState("repo") != ModeShapeEngine.State.RUNNING) { Thread.yield(); } System.out.println("Modeshape is up and running."); if (benchEnabled) { System.out.println("Enter 'S' to start the tests:"); Scanner scan = new Scanner(System.in); while (!scan.hasNextLine()) { Thread.yield(); } String input = scan.next(); if (input.equalsIgnoreCase("s")) { System.out.println("starting tests"); BenchTool tool = new BenchTool(); tool.runBenchMark(repo, num, size, threads); } else { System.out.println("stopping server"); } } }