List of usage examples for java.util Scanner next
public String next()
From source file:main.Draft_text_categorization.java
/** * Devuelve un Set<String> compuesto por los trminos * que aparecen en el archivo txt pasado como parmetro * // www . j av a 2 s . c o m * @param file * @return */ public static Set<String> fileToSet(Scanner file) { Set<String> doc = new HashSet<>(); while (file.hasNext()) { doc.add(file.next().trim().toLowerCase()); } return doc; }
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.openml.knime.OpenMLWebservice.java
/** * Convert an input stream into a string. * /*from ww w . j a va 2 s. c o 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: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. j a v a2 s . c om*/ return args.toArray(new String[0]); }
From source file:se.vgregion.alfresco.repo.scripts.ExportJsonToExcel.java
private static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:com.ingby.socbox.bischeck.servers.NRDPBatchServer.java
@SuppressWarnings("resource") static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
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();/*from w w w. jav a2 s .co m*/ 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:aiai.ai.launchpad.experiment.ExperimentUtils.java
public static NumberOfVariants getNumberOfVariants(String variantsAsStr) { if (StringUtils.isBlank(variantsAsStr)) { return ZERO_VARIANT; }/* w w w . java 2 s .com*/ String s = variantsAsStr.trim(); if (s.charAt(0) != '(' && s.charAt(0) != '[' && !StringUtils.startsWithIgnoreCase(s.toLowerCase(), RANGE)) { final NumberOfVariants variants = new NumberOfVariants(true, null, 1); variants.values.add(s); return variants; } if (s.startsWith("[")) { int count = 0; final NumberOfVariants variants = new NumberOfVariants(true, null, 0); for (StringTokenizer st = new StringTokenizer(s, "[,] "); st.hasMoreTokens();) { String token = st.nextToken(); variants.values.add(token); count++; } variants.count = count; return variants; } String s1 = s; if (StringUtils.startsWithIgnoreCase(s1, RANGE)) { s1 = s1.substring(RANGE.length()).trim(); } if (s1.charAt(0) == '(') { Scanner scanner = new Scanner(s1.substring(1)); scanner.useDelimiter("[,)]"); int start; int end; int change; try { start = Integer.parseInt(scanner.next().trim()); end = Integer.parseInt(scanner.next().trim()); change = Integer.parseInt(scanner.next().trim()); } catch (NumberFormatException | NoSuchElementException e) { return new NumberOfVariants(false, "Wrong string format for string: " + s, 0); } int count = 0; final NumberOfVariants variants = new NumberOfVariants(true, null, 0); for (int i = start; i < end; i += change) { variants.values.add(Integer.toString(i)); count++; if (count > 100) { return new NumberOfVariants(false, "Too many variants for string: " + s, 0); } } variants.count = count; return variants; } return new NumberOfVariants(false, "Wrong number format for string: " + s, 0); }
From source file:com.bb.extensions.plugin.unittests.internal.utilities.FileUtils.java
/** * Convert an input stream to a string//w w w . j a va2 s . c om * * @param stream * The input stream * @return The string contents of the input stream */ public static String toString(java.io.InputStream stream) { Scanner s = new Scanner(stream).useDelimiter("\\A"); //$NON-NLS-1$ return s.hasNext() ? s.next() : ""; //$NON-NLS-1$ }
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 . j a va 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(); } }