List of usage examples for java.util Scanner nextLine
public String nextLine()
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.//from w w w.j a va 2s . 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:ir.ac.ut.snl.mrcd.InputConverter.java
public void convert(String filename) throws FileNotFoundException, UnsupportedEncodingException { int paddingSize = 49; // 50-1; 1 baraye '\n' File file = new File(filename); FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); Scanner scanner = new Scanner(bufferedReader); PrintWriter printWriter = new PrintWriter(filename + "-converted", "UTF-8"); int n = scanner.nextInt(); scanner.nextLine(); printWriter.write(StringUtils.leftPad(String.valueOf(n), paddingSize)); printWriter.write('\n'); while (scanner.hasNextLine()) { String line = scanner.nextLine(); printWriter.write(StringUtils.leftPad(line, paddingSize)); printWriter.write('\n'); }//from w w w .j av a 2 s. com scanner.close(); printWriter.close(); }
From source file:csns.importer.parser.csula.StudentsParserImpl.java
/** * This parser handles data copy&pasted from an Excel file produced from GET * data. The format is expected to be <quarter cin first_name last_name ...> * where quarter is a 4-digit code. Currently we only process the first four * fields./*from w ww .ja v a 2 s. c o m*/ */ @Override public List<ImportedUser> parse(String text) { List<ImportedUser> students = new ArrayList<ImportedUser>(); Scanner scanner = new Scanner(text); while (scanner.hasNextLine()) { ImportedUser student = parseLine(scanner.nextLine()); if (student != null) students.add(student); } scanner.close(); return students; }
From source file:eu.planets_project.services.datatypes.ContentTests.java
/** * @param source The source to read from * @return Returns the content of the source *///from ww w . j a v a 2 s .com 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:DataSci.main.JsonRequestResponseController.java
/** * Read the JSON schema from the file rrsJson.json * //from ww w. j av a 2 s .co m * @param filename It expects a fully qualified file name that contains input JSON file */ public void readJson(String filename) { try { File apiFile = new File(filename); Scanner sc = new Scanner(apiFile); jsonBody = ""; while (sc.hasNext()) { jsonBody += sc.nextLine() + "\n"; } sc.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:javaapplication1.Prog.java
public void run(String[] args) throws JSONException, IOException { int k = 0;// w w w.ja v a2s.c om while (k == 0) { Scanner sc = new Scanner(System.in); System.out.print("your command:"); String i = sc.nextLine(); if ("exit".equals(i)) k = 1; else { if ("help".equals(i)) { System.out.print(help); } else if ("transfer".equals(i)) { System.out.print("user:"); String user = sc.nextLine(); System.out.print("from account:"); String account1 = sc.nextLine(); System.out.print("to account:"); String account2 = sc.nextLine(); System.out.print("amount:"); Long amount = sc.nextLong(); Long amount1 = getAmountfromAcc(account1, user); Long amount2 = getAmountfromAcc(account2, user); JSONObject obj1 = new JSONObject(); JSONObject obj2 = new JSONObject(); obj1.put("name", account1); obj1.put("amount", amount1 - amount); String obj11 = obj1.toString(); transferStuff(obj11, user); obj2.put("name", account2); obj2.put("amount", amount2 + amount); String obj22 = obj2.toString(); transferStuff(obj22, user); System.out.print("accounts updated\n"); } else System.out.print("incorrect command\n"); } } }
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 {/* w ww.ja v a 2 s .co 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:com.acme.TopTagsTupleTest.java
@Test public void tags() throws IOException { final Broadcaster<Object> broadcaster = SerializedBroadcaster.create(); Processor processor = new TopTags(1, 10); Stream<?> outputStream = processor.process(broadcaster); outputStream.consume(new Consumer<Object>() { @Override/*from w w w . j ava 2 s .c o m*/ public void accept(Object o) { System.out.println("processed : " + o); } //TODO - expect // processed : {"id":"55786760-7472-065d-8e62-eb83260948a4","timestamp":1422399628134,"hashtag":"AndroidGames","count":1} // processed : {"id":"bd99050f-abfa-a239-c09a-f2fe721daafb","timestamp":1422399628182,"hashtag":"Android","count":1} // processed : {"id":"10ce993c-fd57-322d-efa1-16f810918187","timestamp":1422399628184,"hashtag":"GameInsight","count":1} }); ClassPathResource resource = new ClassPathResource("tweets.json"); Scanner scanner = new Scanner(resource.getInputStream()); while (scanner.hasNext()) { String tweet = scanner.nextLine(); broadcaster.onNext(tweet); //simulateLatency(); } //System.in.read(); }
From source file:net.praqma.clearcase.test.unit.LoadRules2Test.java
public List<String> mockConsoleOut(String filename) throws Exception { InputStream is;/* ww w .j a va 2s . c o m*/ 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.datasift.serializer.DatasiftInstagramActivitySerializerTest.java
@Test @Override//from www.j a v a 2s . c o m public void testConversion() throws Exception { Scanner scanner = StreamsScannerUtil.getInstance("/instagram_datasift_json.txt"); String line = null; while (scanner.hasNextLine()) { line = scanner.nextLine(); Datasift item = MAPPER.readValue(line, Datasift.class); testConversion(item); String json = MAPPER.writeValueAsString(item); testDeserNoNull(json); testDeserNoAddProps(json); } }