List of usage examples for java.util Scanner hasNextLine
public boolean hasNextLine()
From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java
/** * Initializes the conversion map with some predefined * files. Each file contains a list of FB types associated * (mainly) to a specific type. An additional file contains * a list of ignored types (for debugging purposes, and to * ease the future completion of these files). * /*from ww w .j a v a 2 s. c o m*/ * @throws FileNotFoundException * Problem while accessing one of the map files. */ private synchronized void loadTypeMaps() throws FileNotFoundException { if (TYPE_MAP.isEmpty()) { logger.log("Loading type maps"); logger.increaseOffset(); // set up the list of types String base = FileNames.FO_SUBEE + File.separator; List<EntityType> types = new ArrayList<EntityType>(HANDLED_TYPES); types.add(null); // for the ignored types // process each corresponding file for (EntityType type : types) { // open file String name = FILE_IGNORED; if (type != null) name = type.toString().toLowerCase(); String filePath = base + FILE_PREFIX + name + FileNames.EX_TXT; logger.log("Processing file " + filePath); Scanner scanner = FileTools.openTextFileRead(filePath); // read the content and add to the conversion map while (scanner.hasNextLine()) { String string = scanner.nextLine().trim(); TYPE_MAP.put(string, type); } scanner.close(); } logger.decreaseOffset(); logger.log("Type maps loading complete"); } }
From source file:net.bashtech.geobot.BotManager.java
public void loadGlobalBannedWords() { globalBannedWords.clear();//ww w . j ava 2 s . c o m File f = new File("globalbannedwords.cfg"); if (!f.exists()) try { f.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { Scanner in = new Scanner(f, "UTF-8"); while (in.hasNextLine()) { String line = in.nextLine().replace("\uFEFF", ""); if (line.length() > 0) { if (line.startsWith("REGEX:")) line = line.replaceAll("REGEX:", ""); else line = ".*" + Pattern.quote(line) + ".*"; System.out.println(line); Pattern tempP = Pattern.compile(line, Pattern.CASE_INSENSITIVE); globalBannedWords.add(tempP); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:io.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.java
private String fileToString(File file, String charset) { StringBuilder fileContents = new StringBuilder((int) file.length()); Scanner scanner;//from ww w. j a v a 2 s .c o m try { scanner = new Scanner(file, charset); } catch (FileNotFoundException e) { throw new RuntimeException(e); } String lineSeparator = System.getProperty(LINE_SEPARATOR); try { while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine()).append(lineSeparator); } return fileContents.toString(); } finally { scanner.close(); } }
From source file:commondb.mock.MockResultSet.java
public void loadCSV(Readable in) throws SQLException { final Scanner sc = new Scanner(in); if (!sc.hasNextLine()) { throw new SQLException("empty data source"); }/*from w ww . j a v a 2 s.c o m*/ // load column headers String line = sc.nextLine(); int index = 1; for (String column : splitter.split(line)) { columnMap.put(column, index); index++; } // load data while (sc.hasNextLine()) { line = sc.nextLine(); String[] row = splitter.split(line); rowset.add(row); } sc.close(); }
From source file:net.bashtech.geobot.BotManager.java
public void loadBanPhraseList() { banPhraseLists = new HashMap<Integer, List<Pattern>>(); File f = new File("bannedphrases.cfg"); if (!f.exists()) try {//from w ww .j a v a 2 s. c om f.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { Scanner in = new Scanner(f, "UTF-8"); while (in.hasNextLine()) { String line = in.nextLine().replace("\uFEFF", ""); if (line.length() > 0) { if (line.startsWith("#")) continue; String[] parts = line.split("\\|", 2); int severity = Integer.parseInt(parts[0]); line = parts[1]; if (line.startsWith("REGEX:")) line = line.replaceAll("REGEX:", ""); else line = ".*\\b" + Pattern.quote(line) + "\\b.*"; System.out.println(line); Pattern tempP = Pattern.compile(line, Pattern.CASE_INSENSITIVE); for (int c = severity; c >= 0; c--) { if (!banPhraseLists.containsKey(c)) banPhraseLists.put(c, new LinkedList<Pattern>()); banPhraseLists.get(c).add(tempP); // System.out.println("Adding " + tempP.toString() // + " to s=" + c); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.joliciel.csvLearner.CSVLearner.java
private CSVEventListReader getReader(TrainingSetType trainingSetType, boolean splitEventsByFile) throws IOException { LOG.info("Generating event list from CSV files..."); CSVEventListReader reader = new CSVEventListReader(); reader.setResultFilePath(resultFilePath); reader.setFeatureDirPath(featureDir); reader.setTestSegment(testSegment);//from w ww . j a v a 2s . c om reader.setGroupedFeatureDirPath(groupedFeatureDir); reader.setTrainingSetType(trainingSetType); reader.setIncludedOutcomes(includedOutcomes); reader.setExcludedOutcomes(excludedOutcomes); reader.setSkipUnknownEvents(skipUnknownEvents); reader.setSplitEventsByFile(splitEventsByFile); if (featureFilePath != null) { File featureFile = new File(featureFilePath); Set<String> features = new TreeSet<String>(); Scanner scanner = new Scanner(featureFile); try { while (scanner.hasNextLine()) { features.add(scanner.nextLine().trim().replace(' ', '_')); } } finally { scanner.close(); } reader.setIncludedFeatures(features); } if (testIdFilePath != null) { File testIdFile = new File(testIdFilePath); Set<String> testIds = new TreeSet<String>(); Scanner scanner = new Scanner(testIdFile); try { while (scanner.hasNextLine()) { testIds.add(scanner.nextLine().trim()); } } finally { scanner.close(); } reader.setTestIds(testIds); } reader.read(); return reader; }
From source file:eu.planets_project.pp.plato.action.workflow.CreateExecutablePlanAction.java
private void generateExecutablePlan() { // this is the recommended action String wsdlLocation = selectedPlan.getRecommendation().getAlternative().getAction().getUrl(); // and this is the target format we want to migrate to String targetFormat = selectedPlan.getRecommendation().getAlternative().getAction().getTargetFormat(); String workflowFile = "data/plans/executables/ExecutablePreservationPlan.xml"; InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(workflowFile); // we load the workflow template and fill out the migrate1 service SAXBuilder builder = new SAXBuilder(); Document doc = null;/*www .j a v a 2 s .com*/ try { doc = builder.build(in); } catch (JDOMException e) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Error in template."); log.error(e); return; } catch (IOException e) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Error in template."); log.error(e); return; } Element root = doc.getRootElement(); try { JDOMXPath endpointXPath = new JDOMXPath("services/service[@id='migrate1']/endpoint"); Element endpoint = (Element) endpointXPath.selectSingleNode(root); endpoint.setText(wsdlLocation); String settings = selectedPlan.getRecommendation().getAlternative().getExperiment().getSettings(); if (settings == null) { settings = ""; } Scanner scanner = new Scanner(settings); JDOMXPath migrateServiceXPath = new JDOMXPath("services/service[@id='migrate1']"); Element migrateService = (Element) migrateServiceXPath.selectSingleNode(root); migrateService.setContent(endpoint); Element parameters = new Element("parameters"); Element targetFormatParam = new Element("param"); targetFormatParam .addContent(new Element("name").setText("planets:service/migration/input/migrate_to_fmt")); targetFormatParam.addContent(new Element("value").setText(targetFormat)); parameters.addContent(targetFormatParam); int index; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if ((index = line.indexOf('=')) > 0) { String name = line.substring(0, index); String value = line.substring(index + 1); if (name.length() > 0 && value.length() > 0) { Element param = new Element("param"); param.addContent(new Element("name").setText(name.trim())); param.addContent(new Element("value").setText(value.trim())); parameters.addContent(param); } } } migrateService.addContent(parameters); } catch (JaxenException e) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Error in template."); log.error(e); return; } XMLOutputter outputter = new XMLOutputter(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); try { outputter.output(doc, byteArray); } catch (IOException e) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Error writing the preservation plan workflow."); log.error(e); return; } selectedPlan.getExecutablePlanDefinition().setExecutablePlan(byteArray.toString()); }
From source file:se.lu.nateko.edca.svc.GeoHelper.java
/** * Reads the geometry and attribute data from the local storage * into the active GeographyLayer.//from w w w . j av a 2 s .c o m */ private boolean readIntoGeographyLayer() { Log.d(TAG, "readIntoGeographyLayer() called."); File layerPath = new File(getPath()); File geomFile = new File(layerPath, "geometry.txt"); File attFile = new File(layerPath, "attributes.txt"); try { if (!geomFile.exists()) // If there is no geometry file. Log.i(TAG, "No geometry stored."); else { /* Read the geometry with ID and geometry WKT. */ Scanner scanner = new Scanner(new FileInputStream(geomFile)); try { while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split("[ ]{1}", 2); WKTReader reader = new WKTReader(); switch (mGeoLayer.getTypeMode()) { case GeographyLayer.TYPE_POINT: { Coordinate p = ((Point) reader.read(line[1])).getCoordinate(); mGeoLayer.addGeometry(new LatLng(p.y, p.x), Long.parseLong(line[0])); break; } case GeographyLayer.TYPE_LINE: { Geometry geom = reader.read(line[1]); Log.v(TAG, "Geom type: " + geom.getGeometryType()); if (geom.getGeometryType().equalsIgnoreCase("LineString")) mGeoLayer.addLine((LineString) geom, Long.parseLong(line[0]), true); else if (geom.getGeometryType().equalsIgnoreCase("Point")) { Coordinate p = ((Point) geom).getCoordinate(); mGeoLayer.addGeometry(new LatLng(p.y, p.x)); } break; } case GeographyLayer.TYPE_POLYGON: { Geometry geom = reader.read(line[1]); Log.v(TAG, "Geom type: " + geom.getGeometryType()); if (geom.getGeometryType().equalsIgnoreCase("Polygon")) mGeoLayer.addPolygon((Polygon) reader.read(line[1]), Long.parseLong(line[0]), true); else if (geom.getGeometryType().equalsIgnoreCase("Point")) { Coordinate p = ((Point) geom).getCoordinate(); mGeoLayer.addGeometry(new LatLng(p.y, p.x)); } break; } } } } catch (ParseException e) { Log.e(TAG, e.toString()); return false; } finally { scanner.close(); } } if (!attFile.exists()) // If there is no attribute file. Log.i(TAG, "No attributes stored."); else { /* Read the attributes with ID and field info. */ Scanner scanner = new Scanner(new FileInputStream(attFile)); try { while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split("[;]{1}", -1); for (int i = 0; i < mGeoLayer.getNonGeomFields().size(); i++) mGeoLayer.addAttribute(Long.parseLong(line[0]), mGeoLayer.getNonGeomFields().get(i).getName(), line[i + 1]); } } finally { scanner.close(); } } } catch (IOException e) { Log.e(TAG, e.toString()); return false; } return true; }
From source file:org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.java
/** * Convert given configuration file to a single String * * @param configFileName - file name to convert * @return String with complete lb configuration * @throws FileNotFoundException//from ww w . j av a2s.c o m */ public String createLBConfigString(String configFileName) throws FileNotFoundException { StringBuilder lbConfigString = new StringBuilder(""); File configFile = new File(configFileName); Scanner scanner; scanner = new Scanner(configFile); while (scanner.hasNextLine()) { lbConfigString.append(scanner.nextLine().trim() + "\n"); } return lbConfigString.toString().trim(); }