List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:org.apache.streams.datasift.serializer.DatasiftTwitterActivitySerializerTest.java
@Test @Override/*from w w w . j av a 2s . c o m*/ public void testConversion() throws Exception { Scanner scanner = StreamsScannerUtil.getInstance("/twitter_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); } }
From source file:org.apache.streams.datasift.serializer.DatasiftEventClassifierTest.java
@Test public void testTwitterDetection() throws Exception { Scanner scanner = StreamsScannerUtil.getInstance("/twitter_datasift_json.txt"); String line = null;/*from w w w. j a v a 2 s.c om*/ while (scanner.hasNextLine()) { line = scanner.nextLine(); Datasift datasift = MAPPER.readValue(line, Datasift.class); assert (DatasiftEventClassifier.detectClass(datasift) == Twitter.class); assert (DatasiftEventClassifier.bestSerializer(datasift) instanceof DatasiftTwitterActivitySerializer); } }
From source file:org.apache.streams.datasift.serializer.DatasiftEventClassifierTest.java
@Test public void testInstagramDetection() throws Exception { Scanner scanner = StreamsScannerUtil.getInstance("/instagram_datasift_json.txt"); String line = null;// w w w. ja v a 2s. c o m while (scanner.hasNextLine()) { line = scanner.nextLine(); Datasift datasift = MAPPER.readValue(line, Datasift.class); assert (DatasiftEventClassifier.detectClass(datasift) == Instagram.class); assert (DatasiftEventClassifier .bestSerializer(datasift) instanceof DatasiftInstagramActivitySerializer); } }
From source file:com.alibaba.dubbo.qos.textui.TKv.java
private String filterEmptyLine(String content) { final StringBuilder sb = new StringBuilder(); Scanner scanner = null; try {/*from ww w . j a v a 2 s. c o m*/ scanner = new Scanner(content); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line != null) { // remove extra space at line's end line = StringUtils.stripEnd(line, " "); if (line.isEmpty()) { line = " "; } } sb.append(line).append('\n'); } } finally { if (null != scanner) { scanner.close(); } } return sb.toString(); }
From source file:dsfixgui.FileIO.DSFixFileController.java
public static String readTextFile(String filePath) throws FileNotFoundException { //The file to be read File readFile = new File(filePath); //Initialize Scanner for reading file Scanner fileReader = new Scanner(readFile); //The String to be returned String text = null;// w w w . j a v a 2 s . com while (fileReader.hasNextLine()) { if (text == null) { //Initialize return String text = ""; } else { //Add new linebreak text += String.format("%n"); } //Add line to text text += fileReader.nextLine(); } fileReader.close(); return text; }
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())); }//www.ja v a2 s. co m LOGGER.info("Providing {} docs", persistQueue.size()); StreamsResultSet result = new StreamsResultSet(persistQueue); LOGGER.info("{} Exiting", STREAMS_ID); return result; }
From source file:ng.logentries.logs.LogReader.java
public <T extends LogEntryData> List<T> readLogs(Class<? extends LogEntryData> cls, Account account, FilterOptions options) throws Exception { List<T> list = new ArrayList<>(); LogEntryData instance = cls.newInstance(); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try {/*from www . j a v a2s.co m*/ URIBuilder uriBuilder = new URIBuilder().setScheme("https").setHost("pull.logentries.com/") .setPath(account.getAccessKey() + "/hosts/" + account.getLogSetName() + "/" + account.getLogName() + "/"); if (options.getLimit() != -1) { uriBuilder.addParameter("limit", "" + options.getLimit()); } uriBuilder.addParameter("filter", instance.getPattern()); if (options.getsTime() != -1) { uriBuilder.addParameter("start", "" + options.getsTime()); } if (options.geteTime() != -1) { uriBuilder.addParameter("end", "" + options.geteTime()); System.out.println(options.geteTime()); } HttpGet get = new HttpGet(uriBuilder.build()); HttpResponse httpResponse = httpClient.execute(get); HttpEntity entity = httpResponse.getEntity(); Scanner in = new Scanner(entity.getContent()); while (in.hasNext()) { T parse = (T) LogDataMapper.parse(in.nextLine(), cls); list.add(parse); //System.out.println(parse); } } catch (Exception e) { System.out.println("Error while trying to read logs: " + e); } finally { if (httpClient != null) { httpClient.close(); } } return list; }
From source file:com.chargebee.JDBC.PhoneBook.Phnbk.java
private void process(Connection connection, Statement statement) throws SQLException, Exception { Scanner sc = new Scanner(System.in); System.out.println("Search by : name/number?"); String choice = sc.nextLine(); System.out.println("Enter the " + choice + " : "); String param = sc.nextLine(); if (choice.toLowerCase().equalsIgnoreCase("name")) { detailsName(statement, param, connection); } else if (choice.toLowerCase().equalsIgnoreCase("number")) { detailsNumber(statement, param, connection); } else {//from www . j a v a 2s .co m System.out.println("Invalid Choice!!"); } MethodBank.dropDataBase(statement, dataBaseName); //closeConnection(connection); //closeStatement(statement); }
From source file:net.bashtech.geobot.BotManager.java
public static String postDataLinkShortener(String postData) { URL url;/*from w ww. j av a 2s.com*/ HttpURLConnection conn; postData = "{\"longUrl\": \"" + postData + "\"}"; try { url = new URL("https://www.googleapis.com/urlshortener/v1/url"); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); PrintWriter out = new PrintWriter(conn.getOutputStream()); System.out.println(postData); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; }
From source file:net.bashtech.geobot.BotManager.java
public static String putRemoteData(String urlString, String postData) throws IOException { URL url;//w w w .j a v a 2 s . co m HttpURLConnection conn; try { url = new URL(urlString); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("PUT"); conn.setFixedLengthStreamingMode(postData.getBytes().length); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Accept", "application/vnd.twitchtv.v2+json"); conn.setRequestProperty("Authorization", "OAuth " + BotManager.getInstance().krakenOAuthToken); conn.setRequestProperty("Client-ID", BotManager.getInstance().krakenClientID); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } return ""; }