List of usage examples for java.util Scanner hasNextLine
public boolean hasNextLine()
From source file:configurator.Configurator.java
/** * Method for getting address of configuration file of device by name * * @param name name of device;/*w ww . j a va 2 s.c o m*/ * @return address of configuration file; * @throws FileNotFoundException */ String getAddressByModelName(String name) throws FileNotFoundException { Scanner switchReader = new Scanner(new FileReader("switchlist.txt")); String model; while (switchReader.hasNextLine()) { model = switchReader.nextLine(); if (model.contains(name)) { return model.split("->")[1]; } } return null; }
From source file:me.prokopyl.commandtools.commands.Commands.java
private void initDescriptions() { String fileName = "help/" + getUsualName() + ".txt"; InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName); if (stream == null) { PluginLogger.LogWarning("Could not load description file for the " + getUsualName() + " command"); return;//w ww .ja v a 2 s.co m } Scanner scanner = new Scanner(stream); StringBuilder builder = new StringBuilder(); //Getting the group's description //And then each command's description int colonIndex, firstSpaceIndex; boolean isGroupDescription = true; while (scanner.hasNextLine()) { String line = scanner.nextLine(); colonIndex = line.indexOf(':'); if (isGroupDescription) { firstSpaceIndex = line.indexOf(' '); if (colonIndex > 0 && firstSpaceIndex > colonIndex) isGroupDescription = false; } if (isGroupDescription) { builder.append(line).append('\n'); } else { commandsDescriptions.put(line.substring(0, colonIndex).trim(), line.substring(colonIndex + 1).trim()); } } scanner.close(); description = builder.toString().trim(); }
From source file:fr.zcraft.zlib.components.commands.CommandGroup.java
private void initDescriptions() { String fileName = "help/" + getUsualName() + ".txt"; InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName); if (stream == null) { PluginLogger.warning("Could not load description file for the " + getUsualName() + " command"); return;/*from www. j av a 2 s. c o m*/ } Scanner scanner = new Scanner(stream); StringBuilder builder = new StringBuilder(); //Getting the group's description //And then each command's description int colonIndex, firstSpaceIndex; boolean isGroupDescription = true; while (scanner.hasNextLine()) { String line = scanner.nextLine(); colonIndex = line.indexOf(':'); if (isGroupDescription) { firstSpaceIndex = line.indexOf(' '); if (colonIndex > 0 && firstSpaceIndex > colonIndex) isGroupDescription = false; } if (isGroupDescription) { builder.append(line).append('\n'); } else { commandsDescriptions.put(line.substring(0, colonIndex).trim(), line.substring(colonIndex + 1).trim()); } } scanner.close(); description = builder.toString().trim(); }
From source file:Demo.ScatterGraph.java
private void AddDataSet(int x, int y) { List<Integer> failIndexList = new ArrayList<Integer>(); // read fail index Scanner scan = null; try {/* w w w .j a v a 2 s . com*/ scan = new Scanner(new File("data/failIndex.dat")); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "failIndex.dat File doesn't exist.", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } while (scan.hasNextLine()) { failIndexList.add(Integer.parseInt(scan.nextLine())); } // read X, Y double[] valueX = Utils.GetParaTab(paraType_list.get(x)); double[] valueY = Utils.GetParaTab(paraType_list.get(y)); // create data set double[][] dataSetPass = new double[2][sampleNb - failIndexList.size()]; double[][] dataSetFail = new double[2][failIndexList.size()]; int i_f = 0; int i_p = 0; for (int i = 0; i < sampleNb; i++) { if (failIndexList.contains(new Integer(i + 1))) { dataSetFail[0][i_f] = valueX[i]; dataSetFail[1][i_f] = valueY[i]; i_f++; } else { dataSetPass[0][i_p] = valueX[i]; dataSetPass[1][i_p] = valueY[i]; i_p++; } } dataSet.addSeries("pass", dataSetPass); dataSet.addSeries("fail", dataSetFail); }
From source file:edu.ucuenca.authorsrelatedness.Distance.java
public synchronized String Http2(String s, Map<String, String> mp) throws SQLException, IOException { String md = s + mp.toString(); String get = Cache.getInstance().get(md); String resp = ""; if (get != null) { resp = get;/*from www. ja v a2s . com*/ } else { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(s); method.getParams().setContentCharset("utf-8"); //Add any parameter if u want to send it with Post req. for (Entry<String, String> mcc : mp.entrySet()) { method.addParameter(mcc.getKey(), mcc.getValue()); } int statusCode = client.executeMethod(method); if (statusCode != -1) { InputStream in = method.getResponseBodyAsStream(); final Scanner reader = new Scanner(in, "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); Cache.getInstance().put(md, resp); } } return resp; }
From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed if (connectButton.getText().equals("Connect")) { // attempt to connect to the serial port chosenPort = SerialPort.getCommPort(portList.getSelectedItem().toString()); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); if (chosenPort.openPort()) { connectButton.setText("Disconnect"); portList.setEnabled(false);/*from ww w.j av a 2 s.co m*/ } portThread = new Thread() { @Override public void run() { Scanner scanner = new Scanner(chosenPort.getInputStream()); try { Thread.currentThread().setName("Port Reader"); while (true) { while (scanner.hasNextLine()) { try { String line = scanner.nextLine(); ZY1270Data data = ZY1270Data.parseString(line, new Date()); ((DefaultTableModel) resultTable.getModel()).addRow(data.getRowFormat()); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { resultTable.scrollRectToVisible( resultTable.getCellRect(resultTable.getRowCount() - 1, resultTable.getColumnCount(), true)); } }); ampSeries.add(new Millisecond(data.getTimestamp()), data.getAmp()); voltageSeries.add(new Millisecond(data.getTimestamp()), data.getVoltage()); wattSeries.add(new Millisecond(data.getTimestamp()), data.getWatt()); } catch (Exception e) { } } Thread.sleep(1); } } catch (Exception e) { } finally { scanner.close(); } } }; portThread.start(); } else { // disconnect from the serial port new Thread() { @Override public void run() { while (!portThread.isInterrupted()) { portThread.interrupt(); } chosenPort.closePort(); portList.setEnabled(true); connectButton.setText("Connect"); } }.start(); } }
From source file:org.apache.uima.ruta.resource.TreeWordList.java
/** * Creates a new Tree in the existing treeWordList from a file with path pathname * // w ww . j av a2 s . c o m * @param stream * Open InputStream containing the word for the treeWordList, this method will close the * stream. */ public void buildNewTree(InputStream stream) throws IOException { Scanner scan = new Scanner(stream, "UTF-8"); // creating a new tree this.root = new TextNode(); while (scan.hasNextLine()) { String s = scan.nextLine().trim(); // HOTFIX for old formats if (s.endsWith("=")) { s = s.substring(0, s.length() - 1); s = s.trim(); } addWord(s); } scan.close(); }
From source file:edu.ucuenca.authorsrelatedness.Distance.java
public synchronized String Http(String s) throws SQLException, IOException { String get = Cache.getInstance().get(s); String resp = ""; if (get != null) { //System.out.print("."); resp = get;/*from w w w . ja va 2s .c o m*/ } else { final URL url = new URL(s); final URLConnection connection = url.openConnection(); connection.setConnectTimeout(60000); connection.setReadTimeout(60000); connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0"); connection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); final Scanner reader = new Scanner(connection.getInputStream(), "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); Cache.getInstance().put(s, resp); } return resp; }
From source file:com.l2jfree.gameserver.datatables.ExtractableItemsData.java
private ExtractableItemsData() { _items.clear();/*from w ww. ja v a 2 s . c om*/ Scanner s; try { s = new Scanner(new File(Config.DATAPACK_ROOT, "data/extractable_items.csv")); } catch (Exception e) { _log.warn("Extractable items data: Can not find '" + Config.DATAPACK_ROOT + "data/extractable_items.csv'"); return; } int lineCount = 0; while (s.hasNextLine()) { lineCount++; String line = s.nextLine().trim(); if (line.startsWith("#")) continue; else if (line.isEmpty()) continue; String[] lineSplit = line.split(";"); boolean ok = true; int itemID = 0; try { itemID = Integer.parseInt(lineSplit[0]); } catch (Exception e) { _log.warn("Extractable items data: Error in line " + lineCount + " -> invalid item id or wrong seperator after item id!"); _log.warn(" " + line); ok = false; } if (!ok) continue; FastList<L2ExtractableProductItem> product_temp = new FastList<L2ExtractableProductItem>(); for (int i = 0; i < lineSplit.length - 1; i++) { ok = true; String[] lineSplit2 = lineSplit[i + 1].split(","); if (lineSplit2.length < 3) { _log.warn("Extractable items data: Error in line " + lineCount + " -> wrong seperator!"); _log.warn(" " + line); ok = false; } if (!ok) continue; int[] production = null; int[] amount = null; int chance = 0; try { int k = 0; production = new int[(lineSplit2.length - 1) / 2]; amount = new int[(lineSplit2.length - 1) / 2]; for (int j = 0; j < lineSplit2.length - 1; j++) { production[k] = Integer.parseInt(lineSplit2[j]); amount[k] = Integer.parseInt(lineSplit2[j += 1]); k++; } chance = Integer.parseInt(lineSplit2[lineSplit2.length - 1]); } catch (Exception e) { _log.warn("Extractable items data: Error in line " + lineCount + " -> incomplete/invalid production data or wrong seperator!"); _log.warn(" " + line); ok = false; } if (!ok) continue; L2ExtractableProductItem product = new L2ExtractableProductItem(production, amount, chance); product_temp.add(product); } int fullChances = 0; for (L2ExtractableProductItem Pi : product_temp) fullChances += Pi.getChance(); if (fullChances > 100) { _log.warn("Extractable items data: Error in line " + lineCount + " -> all chances together are more then 100!"); _log.warn(" " + line); continue; } L2ExtractableItem product = new L2ExtractableItem(itemID, product_temp); _items.put(itemID, product); } s.close(); _log.info("Extractable items data: Loaded " + _items.size() + " extractable items!"); }
From source file:ai.grakn.graql.GraqlShell.java
private void printLicense() { StringBuilder result = new StringBuilder(""); //Get file from resources folder ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream(LICENSE_LOCATION); Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name()); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); }//from w w w.j ava 2s .c o m result.append("\n"); scanner.close(); this.print(result.toString()); }