List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:org.eclipse.om2m.comm.http.RestHttpServlet.java
static String convertStreamToString(InputStream is) { Scanner scanner = new Scanner(is); scanner.useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; }
From source file:org.wso2.carbon.la.core.utils.LogPatternExtractor.java
public static Map<String, String> processDelimiter(String logLine, String delimiter) { String value = null;// w w w .jav a 2 s.c o m String delemiterConf = null; Map<String, String> logEvent = new HashMap<>(); switch (delimiter) { case "space": delemiterConf = LAConstants.DELIMITER_SPACE; break; case "comma": delemiterConf = LAConstants.DELIMITER_COMMA; break; case "pipe": delemiterConf = LAConstants.DELIMITER_PIPE; break; case "tab": delemiterConf = LAConstants.DELIMITER_TAB; break; default: delemiterConf = delimiter; break; } // Initialize Scanner object Scanner scan = new Scanner(logLine.trim()); // initialize the string delimiter scan.useDelimiter(delemiterConf.trim()); int fieldIndex = 0; while (scan.hasNext()) { String fieldName = "field" + fieldIndex; logEvent.put(fieldName, scan.next()); fieldIndex++; } // closing the scanner stream scan.close(); return logEvent; }
From source file:at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl.java
private static void loadXAdES14Blacklist() { XADES_1_4_BLACKLIST_TS = System.currentTimeMillis(); XADES_1_4_BLACKLIST.clear();/*w w w . ja v a 2 s . c om*/ try { URLConnection blc = new URL(ConfigurationFacade.XADES_1_4_BLACKLIST_URL).openConnection(); blc.setUseCaches(false); InputStream in = blc.getInputStream(); Scanner s = new Scanner(in); while (s.hasNext()) { XADES_1_4_BLACKLIST.add(s.next()); } s.close(); } catch (Exception e) { log.error("Blacklist load error", e); } }
From source file:org.kercoin.magrit.ArgumentsParserTest.java
static String[] split(String cmdLine) { Scanner s = new Scanner(cmdLine); s.useDelimiter(Pattern.compile("\\s+")); List<String> args = new ArrayList<String>(); while (s.hasNext()) { args.add(s.next());//from w ww . jav a 2 s .co m } return args.toArray(new String[0]); }
From source file:nbayes_mr.NBAYES_MR.java
public static void splitter(String fname) { String filePath = new File("").getAbsolutePath(); Integer count = 0;/*from w w w .ja v a 2 s. c o m*/ try { Scanner s = new Scanner(new File(fname)); while (s.hasNext()) { count++; s.next(); } Integer cnt5 = count / 5; System.out.println(count); System.out.println(cnt5); Scanner sc = new Scanner(new File(fname)); File file1 = new File("/home/hduser/data1.txt"); File file2 = new File("/home/hduser/data2.txt"); File file3 = new File("/home/hduser/data3.txt"); File file4 = new File("/home/hduser/data4.txt"); File file5 = new File("/home/hduser/data5.txt"); file1.createNewFile(); file2.createNewFile(); file3.createNewFile(); file4.createNewFile(); file5.createNewFile(); FileWriter fw1 = new FileWriter(file1.getAbsoluteFile()); BufferedWriter bw1 = new BufferedWriter(fw1); FileWriter fw2 = new FileWriter(file2.getAbsoluteFile()); BufferedWriter bw2 = new BufferedWriter(fw2); FileWriter fw3 = new FileWriter(file3.getAbsoluteFile()); BufferedWriter bw3 = new BufferedWriter(fw3); FileWriter fw4 = new FileWriter(file4.getAbsoluteFile()); BufferedWriter bw4 = new BufferedWriter(fw4); FileWriter fw5 = new FileWriter(file5.getAbsoluteFile()); BufferedWriter bw5 = new BufferedWriter(fw5); for (int i = 0; i < cnt5; i++) { String l = sc.next(); bw1.write(l + "\n"); } for (int i = cnt5; i < 2 * cnt5; i++) { bw2.write(sc.next() + "\n"); } for (int i = 2 * cnt5; i < 3 * cnt5; i++) { bw3.write(sc.next() + "\n"); } for (int i = 3 * cnt5; i < 4 * cnt5; i++) { bw4.write(sc.next() + "\n"); } for (int i = 4 * cnt5; i < count; i++) { bw5.write(sc.next() + "\n"); } bw1.close(); bw2.close(); bw3.close(); bw4.close(); bw5.close(); sc.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.openml.knime.OpenMLWebservice.java
/** * Convert an input stream into a string. * /* ww w . j a v a 2 s . co m*/ * * @param is The input stream * @return Content of the input stream as a string */ private static String convertStreamToString(InputStream is) { Scanner s = new Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:net.firejack.platform.core.utils.StringUtils.java
/** * @param value//from w ww. java 2 s .c om * @param replacement * @return */ public static String changeWhiteSpacesWithSymbol(String value, String replacement) { if (StringUtils.isBlank(value)) { return ""; } if (replacement == null) { throw new IllegalArgumentException("Could not process value using replacement which is null."); } StringBuilder sb = new StringBuilder(); Scanner sc = new Scanner(value); sb.append(sc.next()); while (sc.hasNext()) { sb.append(replacement).append(sc.next()); } return sb.toString(); }
From source file:dm_p2.KMEANS.java
public static void generateLinkedHashMap(String filename) { String filePath = new File("").getAbsolutePath(); try {// www.ja v a2 s.com Scanner s = new Scanner(new File(filePath + "/src/dm_p2/" + filename)); while (s.hasNext()) { String inputLine = s.nextLine(); String[] splitData = inputLine.split("\t"); int geneId = Integer.parseInt(splitData[0]); int valgeneId = Integer.parseInt(splitData[1]); expressionValues = new ArrayList<Double>(); for (int i = 2; i < splitData.length; i++) { expressionValues.add(Double.parseDouble(splitData[i])); } linkedHashMap.put(geneId, expressionValues); if (valgeneId != -1) { validationMap.put(geneId, valgeneId); } } //System.out.println(linkedHashMap.entrySet()); //System.out.println(validationMap.entrySet()); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java
/** * Prints the sample properties file on the default output. *//*from w ww . j a v a 2s.co m*/ private static void printSamplePropertiesFile() { System.out.println("\n File: kratubackend-sample.properties example"); ClassPathResource sampleFile = new ClassPathResource(CLASSPATH_AW_REPORT_MODEL_PROPERTIES_LOCATION); Scanner fileScanner = null; try { fileScanner = new Scanner(sampleFile.getInputStream()); while (fileScanner.hasNext()) { System.out.println(fileScanner.nextLine()); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fileScanner != null) { fileScanner.close(); } } }
From source file:com.microsoft.intellij.util.WAHelper.java
/** * This API compares if two files content is identical. It ignores extra * spaces and new lines while comparing/*from ww w . j av a2s.co m*/ * * @param sourceFile * @param destFile * @return * @throws Exception */ public static boolean isFilesIdentical(URL sourceFile, File destFile) throws Exception { try { Scanner sourceFileScanner = new Scanner(sourceFile.openStream()); Scanner destFileScanner = new Scanner(destFile); while (sourceFileScanner.hasNext()) { /* * If source file is having next token then destination file * also should have next token, else they are not identical. */ if (!destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } if (!sourceFileScanner.next().equals(destFileScanner.next())) { sourceFileScanner.close(); destFileScanner.close(); return false; } } /* * Handling the case where source file is empty and destination file * is having text */ if (destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } else { destFileScanner.close(); sourceFileScanner.close(); return true; } } catch (Exception e) { e.printStackTrace(); throw e; } /*finally { sourceFile.close(); }*/ }