List of usage examples for java.util Scanner hasNextLine
public boolean hasNextLine()
From source file:languages.TabFile.java
/** * Reads the content of the specified *.tab file to this objects variables. * * @param file The file to read./*from ww w .j a v a 2 s. c o m*/ * @throws IOException if the file cannot be read. */ private void readFile(URL file) throws IOException { // open the file Scanner scan = new Scanner(file.openStream(), "UTF-8"); // get the column headers columnHeaders = scan.nextLine().split(" "); while (scan.hasNextLine()) { ArrayListWithSortableKey<String> temp = new ArrayListWithSortableKey<>( Arrays.asList(scan.nextLine().split(" "))); while (temp.size() < this.getColumnCount()) { // Fill it up temp.add(""); } values.add(temp); } scan.close(); }
From source file:org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.java
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception { BindyCsvFactory factory = (BindyCsvFactory) getFactory(exchange.getContext().getPackageScanClassResolver()); ObjectHelper.notNull(factory, "not instantiated"); // List of Pojos List<Map<String, Object>> models = new ArrayList<Map<String, Object>>(); // Pojos of the model Map<String, Object> model; InputStreamReader in = new InputStreamReader(inputStream); // Scanner is used to read big file Scanner scanner = new Scanner(in); // Retrieve the separator defined to split the record String separator = factory.getSeparator(); ObjectHelper.notNull(separator, "The separator has not been defined in the annotation @CsvRecord or not instantiated during initModel."); int count = 0; try {//from w w w. j ava 2s . com // If the first line of the CSV file contains columns name, then we // skip this line if (factory.getSkipFirstLine()) { // Check if scanner is empty if (scanner.hasNextLine()) { scanner.nextLine(); } } while (scanner.hasNextLine()) { // Read the line String line = scanner.nextLine().trim(); if (ObjectHelper.isEmpty(line)) { // skip if line is empty continue; } // Increment counter count++; // Create POJO where CSV data will be stored model = factory.factory(); // Split the CSV record according to the separator defined in // annotated class @CSVRecord String[] tokens = line.split(separator, -1); List<String> result = Arrays.asList(tokens); // must unquote tokens before use result = unquoteTokens(result); if (result.size() == 0 || result.isEmpty()) { throw new java.lang.IllegalArgumentException("No records have been defined in the CSV !"); } if (result.size() > 0) { if (LOG.isDebugEnabled()) { LOG.debug("Size of the record splitted : " + result.size()); } // Bind data from CSV record with model classes factory.bind(result, model, count); // Link objects together factory.link(model); // Add objects graph to the list models.add(model); if (LOG.isDebugEnabled()) { LOG.debug("Graph of objects created : " + model); } } } // Test if models list is empty or not // If this is the case (correspond to an empty stream, ...) if (models.size() == 0) { throw new java.lang.IllegalArgumentException("No records have been defined in the CSV !"); } else { return models; } } finally { scanner.close(); IOHelper.close(in, "in", LOG); } }
From source file:com.joliciel.csvLearner.CSVEventListReader.java
void scanResultsFile() throws IOException { if (this.resultFilePath != null) { // have results Scanner resultScanner = new Scanner(new FileInputStream(resultFilePath), "UTF-8"); try {/*from www . ja va 2s .c o m*/ int i = 0; boolean firstLine = true; while (resultScanner.hasNextLine()) { String line = resultScanner.nextLine(); if (!firstLine) { List<String> cells = CSVFormatter.getCSVCells(line); String ref = cells.get(0); String outcome = cells.get(1); boolean includeEvent = true; if (includedOutcomes != null) { if (!includedOutcomes.contains(outcome)) includeEvent = false; } else if (excludedOutcomes != null) { if (excludedOutcomes.contains(outcome)) includeEvent = false; } if (includeEvent) { if (eventMap.containsKey(ref)) { throw new RuntimeException("Duplicate identifier in result file: " + ref); } GenericEvent event = new GenericEvent(ref); outcomes.add(outcome); event.setOutcome(outcome); if (testIds != null) { if (testIds.contains(ref)) event.setTest(true); else event.setTest(false); } else if (trainingSetType.equals(TrainingSetType.ALL_TRAINING)) { event.setTest(false); } else if (trainingSetType.equals(TrainingSetType.ALL_TEST)) { event.setTest(true); } else if (trainingSetType.equals(TrainingSetType.TEST_SEGMENT)) { event.setTest(i % 10 == testSegment); } else { throw new RuntimeException("Unknown TrainingSetType: " + trainingSetType); } eventMap.put(ref, event); i++; } else { eventsToExclude.add(ref); } } firstLine = false; } } finally { resultScanner.close(); } } // have results }
From source file:com.syncleus.maven.plugins.mongodb.StartMongoMojo.java
private void processScriptFile(final DB db, final File scriptFile) throws MojoExecutionException { Scanner scanner = null; final StringBuilder instructions = new StringBuilder(); try {/*w w w . j av a2 s . c o m*/ scanner = new Scanner(scriptFile); while (scanner.hasNextLine()) { instructions.append(scanner.nextLine()).append("\n"); } } catch (final FileNotFoundException e) { throw new MojoExecutionException("Unable to find file with name '" + scriptFile.getName() + "'", e); } finally { if (scanner != null) { scanner.close(); } } final CommandResult result; try { final String evalString = "(function() {" + instructions.toString() + "})();"; result = db.doEval(evalString, new Object[0]); } catch (final MongoException e) { throw new MojoExecutionException("Unable to execute file with name '" + scriptFile.getName() + "'", e); } if (!result.ok()) { getLog().error("- file " + scriptFile.getName() + " parsed with error: " + result.getErrorMessage()); throw new MojoExecutionException("Error while executing instructions from file '" + scriptFile.getName() + "': " + result.getErrorMessage(), result.getException()); } getLog().info("- file " + scriptFile.getName() + " parsed successfully"); }
From source file:bankingclient.ChonThaoTacFrame.java
public ChonThaoTacFrame(NewOrOldAccFrame acc) { initComponents();// w w w .j a v a 2s . c o m jTextField1.setText(""); jLabel4.setVisible(false); jComboBox2.setVisible(false); jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); jBt_xn2.setVisible(false); this.accList = null; this.cusList = null; this.noAcc = acc; this.tt = new Thong_Tin_TK(this); this.setVisible(false); jBt_xn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (NumberUtils.isNumber(jTextField1.getText()) && (Long.parseLong(jTextField1.getText()) > 0)) { long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } if (jCheck_gt.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(5); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy ra...."); } JOptionPane.showMessageDialog(rootPane, "Gi Ti?n Thnh Cng..."); } if (jCheck_rt.isSelected()) { if ((Long.parseLong(jTextField1.getText()) <= currentMoney)) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(6); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra....."); } JOptionPane.showMessageDialog(rootPane, "Rt Ti?n Thnh Cng ..."); } else { System.out.println("Khng Ti?n Trong ti khon.." + currentMoney); JOptionPane.showMessageDialog(null, "Ti Khon Khng ? ? Rt ..."); } } noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } else { JOptionPane.showMessageDialog(rootPane, "Cn Nhp Li S Ti?n Cn Gi Hoc Rt.."); } } }); jBt_tt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tt.setTk((String) jComboBox1.getSelectedItem()); tt.hienTenTk(); long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); // System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } tt.hienSoDu(((Long) currentMoney).toString()); tt.setVisible(true); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(10); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner cusScanner = new Scanner(din.readUTF()); while (cusScanner.hasNextLine()) { tt.addCus(cusScanner.nextLine()); } } catch (Exception ee) { ee.printStackTrace(); } tt.hienChuTaiKhoan(); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(12); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner dateScanner = new Scanner(din.readUTF()); int day = Integer.parseInt(dateScanner.nextLine()); int month = Integer.parseInt(dateScanner.nextLine()); int year = Integer.parseInt(dateScanner.nextLine()); String date = (day + "-" + month + "-" + year); tt.hienNgayLapTaiKhoan(date); while (dateScanner.hasNextLine()) { // System.out.println("aaa"); tt.addGiaoDich(dateScanner.nextLine()); } tt.hienGiaoDich(); } catch (Exception ex) { ex.printStackTrace(); } ChonThaoTacFrame.this.setVisible(false); } }); jBt_xn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(7); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + (String) jComboBox2.getSelectedItem()); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra\n Thm Ch Tht Bi..."); } JOptionPane.showMessageDialog(rootPane, "Thm Ch Ti Khon Thnh Cng.."); } else { System.out.println("nothing to do..."); } } }); jBt_xtk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(11); String sent = (String) (jComboBox1.getSelectedItem()) + "\n" + noAcc.getCustomer(); dout.writeUTF(sent); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); byte check = din.readByte(); if (check == 1) { JOptionPane.showMessageDialog(rootPane, "xoa tai khoan thanh cong"); } else { JOptionPane.showMessageDialog(rootPane, "<html>xoa tai khoan <b>khong</b> thanh cong <br> chi chu chinh moi co the xoa tai khoan</html>"); } } catch (Exception ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li Kt Ni ,Vui Lng Kim Tra Li.."); } } }); /*dont touch*/ jBt_ql.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } }); /*dont touch*/ jComboBox1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); jComboBox2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); /*dont touch jcheckbox*/ jCheck_tctk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { jLabel4.setVisible(true); jComboBox2.setVisible(true); jBt_xn2.setVisible(true); } else { jLabel4.setVisible(false); jComboBox2.setVisible(false); jBt_xn2.setVisible(false); } } }); jCheck_gt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_gt.isSelected()) { if (jCheck_rt.isSelected()) { jCheck_rt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); jCheck_rt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_rt.isSelected()) { if (jCheck_gt.isSelected()) { jCheck_gt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); /*dont touch jcheckbox*/ }
From source file:ca.weblite.codename1.ios.CodenameOneIOSBuildTask.java
/** * Returns modified Xcode project file contents after removing a set of files from the "Application" * group./*from w ww . j a v a 2 s.c o m*/ * @param projFileContent The Xcode project file contents. * @param filesToRemove A list of files to remove. * @return The modified project file contents. */ protected String removeFilesFromXcodeProject(String projFileContent, File[] filesToRemove) { StringBuilder sb = new StringBuilder(); Scanner scanner = new Scanner(projFileContent); while (scanner.hasNextLine()) { String line = scanner.nextLine(); boolean found = false; for (File f : filesToRemove) { if (line.indexOf("/* " + f.getName() + " */") >= 0) { found = true; } } if (!found) { sb.append(line).append("\n"); } } return sb.toString(); }
From source file:com.jforce.chapelhillnextbus.HomeActivity.java
public void updateDrawerTime() { Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a"); String time = timeFormat.format(calendar.getTime()); TextView tv = (TextView) findViewById(R.id.weather_text); String currentText = tv.getText().toString(); Scanner scanner = new Scanner(currentText); ArrayList<String> lines = new ArrayList<String>(); while (scanner.hasNextLine()) { lines.add(scanner.nextLine());// w w w . j a va 2 s. c o m } String string = ""; for (int i = 0; i < lines.size() - 1; i++) { string = string + lines.get(i) + "\n"; } string = string + time; tv.setText(string); // YoYo.with(Techniques.FadeIn) // .playOn(tv); }
From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java
/** * Loads the existing list of unknown Freebase types. * This list is supposed to be processed manually, * in order to complete the other FB-related files of * Subee. The goal is to associate an EntityType value * to all FB types.// ww w .j ava 2 s.co m */ private synchronized void loadUnknownTypes() { if (UNKNOWN_TYPES.isEmpty()) { logger.log("Loading unknown Freebase types"); logger.increaseOffset(); // set up file path String path = FileNames.FO_SUBEE + File.separator + FileNames.FI_UNKNOWN_TYPES; File file = new File(path); // retrieve existing unknown types try { Scanner scanner = FileTools.openTextFileRead(file); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); UNKNOWN_TYPES.add(line); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } logger.decreaseOffset(); logger.log("Loading complete"); } }
From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java
/** * Loads the list of demonyms. It is supposed to contain only * unambiguous demonyms, i.e. strings which are not at the same * time the adjective and the name of the place. We want to keep * locations./*from ww w . ja va2 s . c o m*/ */ private synchronized void loadDemonyms() { if (DEMONYMS.isEmpty()) { logger.log("Loading demonyms"); logger.increaseOffset(); // set up file path String path = FileNames.FO_CUSTOM_LISTS + File.separator + FileNames.FI_DEMONYMS; File file = new File(path); // retrieve demonyms try { Scanner scanner = FileTools.openTextFileRead(file); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); DEMONYMS.add(line); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } logger.decreaseOffset(); logger.log("Loading complete"); } }
From source file:com.wikitude.phonegap.WikitudePlugin.java
/** * /* w w w . j av a 2 s.c om*/ * @return true if device chip has neon-command support */ private boolean hasNeonSupport() { /* Read cpu info */ FileInputStream fis; try { fis = new FileInputStream("/proc/cpuinfo"); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return false; } Scanner scanner = new Scanner(fis); boolean neonSupport = false; try { while (scanner.hasNextLine()) { if (!neonSupport && (scanner.findInLine("neon") != null)) { neonSupport = true; } scanner.nextLine(); } } catch (Exception e) { Log.i("Wikitudeplugin", "error while getting info about neon support" + e.getMessage()); e.printStackTrace(); } finally { scanner.close(); } return neonSupport; }