List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:com.theminequest.MineQuest.SQLExecutor.java
/** * Check for initialization. What this does is take the build number * and uses a fast forward mechanism from the previous build to see * if any changes should be merged.<br> * It acts similarly to SVN.//ww w . ja v a2 s . com */ private void checkInitialization() { if (!datafolder.exists()) { datafolder.mkdir(); } File versionfile = new File(datafolder + File.separator + "version"); Scanner s = null; String lastv = null; try { s = new Scanner(versionfile); if (s.hasNextLine()) { String dbtype = s.nextLine(); if (dbtype.equalsIgnoreCase(databasetype.name())) { if (s.hasNextLine()) lastv = s.nextLine(); } } } catch (FileNotFoundException e) { try { versionfile.createNewFile(); } catch (IOException e1) { throw new RuntimeException(e1); } } if (lastv == null || lastv.compareTo(MineQuest.getVersion()) != 0) { if (lastv == null || lastv.equals("unofficialDev")) { if (lastv == null) MineQuest.log(Level.WARNING, "[SQL] No existing DBVERSION file; initializing DB as new."); else MineQuest.log(Level.WARNING, "[SQL] I don't know what your previous build was; attempting to reinitialize."); lastv = "initial"; } if (lastv != null && !lastv.equals("unofficialDev") && !lastv.equals("initial")) { int last = Integer.parseInt(lastv); MineQuest.log(Level.INFO, "[SQL] Fast forwarding through builds..."); while (last < Integer.parseInt(MineQuest.getVersion())) { try { MineQuest.log("[SQL] Fast forwarding from build " + last + " to " + (last + 1) + "..."); querySQL("update/" + last, ""); MineQuest.log("[SQL] Applied patch for build " + last + " to " + (last + 1) + "!"); } catch (NoSuchElementException e) { //MineQuest.log(Level.WARNING,"[SQL] No update path from build " + last + " to " + (last+1) + " build; Probably normal."); } last++; } } else { try { querySQL("update/" + lastv, ""); } catch (NoSuchElementException e) { MineQuest.log(Level.WARNING, "[SQL] No update path from build " + lastv + " to this build; Probably normal."); } } Writer out; try { out = new OutputStreamWriter(new FileOutputStream(versionfile)); out.write(databasetype.name() + IOUtils.LINE_SEPARATOR + MineQuest.getVersion()); out.close(); } catch (FileNotFoundException e) { MineQuest.log(Level.SEVERE, "[SQL] Failed to commit DBVERSION: " + e.getMessage()); throw new RuntimeException(e); } catch (IOException e) { MineQuest.log(Level.SEVERE, "[SQL] Failed to commit DBVERSION: " + e.getMessage()); throw new RuntimeException(e); } } }
From source file:com.logisima.selenium.server.action.StaticAction.java
@Override public void execute() { this.setContentType(); try {//from w w w . j a va 2 s . c o m if (request.getUri().endsWith(".png") | request.getUri().endsWith(".gif")) { File image = new File(documentRoot.getAbsolutePath() + request.getUri()); this.content = ChannelBuffers.copiedBuffer(FileUtils.readFileToByteArray(image)); } else { // Process the request StringBuilder buf = new StringBuilder(); buf.setLength(0); Scanner scanner = null; String fileName = documentRoot.getAbsolutePath() + request.getUri().split("[?]")[0]; String NL = System.getProperty("line.separator"); scanner = new Scanner(new FileInputStream(fileName), "utf-8"); while (scanner.hasNextLine()) { buf.append(scanner.nextLine() + NL); } this.content = ChannelBuffers.copiedBuffer(buf.toString(), CharsetUtil.UTF_8); } } catch (FileNotFoundException e) { this.status = HttpResponseStatus.NOT_FOUND; this.content = ChannelBuffers.copiedBuffer(e.toString(), CharsetUtil.UTF_8); } catch (IOException e) { this.status = HttpResponseStatus.INTERNAL_SERVER_ERROR; this.content = ChannelBuffers.copiedBuffer(e.toString(), CharsetUtil.UTF_8); } }
From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java
/** * Cleans the received fileName according to the rules defined in filename_replace_expressions.txt * @param fileName the name to clean/*from www. j av a 2 s. c o m*/ * @return the cleaned name */ private static String getCleanName(String fileName) { File configFile = new File(FilenameUtils.concat(PMS.getConfiguration().getProfileDirectory(), "filename_replace_expressions.txt")); String res = fileName; Scanner scanner = null; try { scanner = new Scanner(new FileInputStream(configFile.getAbsolutePath()), "UTF-8"); String regex; String replaceText; while (scanner.hasNextLine()) { regex = scanner.nextLine(); if (scanner.hasNextLine()) { replaceText = scanner.nextLine(); } else { break; } res = res.replaceAll(regex, replaceText); } } catch (FileNotFoundException e) { if (log.isDebugEnabled()) log.debug(String.format("File '%s' not found. Ignore file name cleaning", configFile.getAbsolutePath())); } finally { if (scanner != null) { scanner.close(); } } res = res.trim(); if (!res.equals(fileName)) { if (log.isInfoEnabled()) log.info(String.format("Cleaned up file '%s' to '%s'", fileName, res)); } return res; }
From source file:io.mindmaps.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); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); }/* ww w . ja v a 2 s . c o m*/ result.append("\n"); scanner.close(); this.print(result.toString()); }
From source file:org.pathwaycommons.pcviz.service.PathwayCommonsGraphService.java
@Cacheable("metadataCache") public String getMetadata(String datatype) { String urlStr = getPathwayCommonsUrl() + "/metadata/" + datatype; try {//from w w w. ja v a 2s. c om URL url = new URL(urlStr); URLConnection urlConnection = url.openConnection(); StringBuilder builder = new StringBuilder(); Scanner scanner = new Scanner(urlConnection.getInputStream()); while (scanner.hasNextLine()) { builder.append(scanner.nextLine() + "\n"); } scanner.close(); return builder.toString(); } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:org.kuali.mobility.knowledgebase.service.KnowledgeBaseServiceImpl.java
private String inputStreamToString(InputStream in) { StringBuffer sb = new StringBuffer(); try {/* ww w .j a v a 2s .c o m*/ Scanner scanner = new Scanner(in); try { while (scanner.hasNextLine()) { sb.append(scanner.nextLine() + "\r\n"); } } finally { scanner.close(); } } catch (Exception e) { // LOG.error("Error retrieving XSL: ", e); } return sb.toString(); }
From source file:com.joliciel.csvLearner.EventCombinationGenerator.java
void scanResultsFile() { Scanner resultScanner; try {//from w w w.j a v a 2 s . co m resultScanner = new Scanner(new FileInputStream(resultFilePath), "UTF-8"); try { 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); List<String> eventsForThisOutcome = this.eventsPerOutcome.get(outcome); if (eventsForThisOutcome == null) { eventsForThisOutcome = new ArrayList<String>(); this.eventsPerOutcome.put(outcome, eventsForThisOutcome); } eventsForThisOutcome.add(ref); } firstLine = false; } } finally { resultScanner.close(); } } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:edu.brandeis.cs.nlp.mae.io.DTDLoader.java
public boolean read(InputStream stream) throws MaeIODTDException, MaeDBException { Scanner sc = new Scanner(stream, "UTF-8"); int lineNum = 1; while (sc.hasNextLine()) { String next = sc.nextLine(); // getting rid of comments if (next.contains("<!--")) { while (sc.hasNextLine() && !next.contains("-->")) { next = sc.nextLine();// w w w . j a v a2 s. c om lineNum++; } next = sc.nextLine(); } //then, concatenate lines about a tag into one string String element = ""; if (next.contains("<")) { element += next; while (sc.hasNextLine() && !next.contains(">")) { next = sc.nextLine(); lineNum++; element += next; } } lineNum++; // remove some problematic unicode characters before processing element = normalizeLine(element); process(element, lineNum); } validateLinkTagTypes(); return validateReadTask(); }
From source file:io.proleap.cobol.preprocessor.sub.document.impl.CobolDocumentParserListenerImpl.java
protected String buildLines(final String text, final String linePrefix) { final StringBuffer sb = new StringBuffer(text.length()); final Scanner scanner = new Scanner(text); boolean firstLine = true; while (scanner.hasNextLine()) { final String line = scanner.nextLine(); if (!firstLine) { sb.append(CobolPreprocessor.NEWLINE); }//from ww w. jav a2 s .com sb.append(linePrefix + CobolPreprocessor.WS + line.trim()); firstLine = false; } scanner.close(); return sb.toString(); }
From source file:com.networknt.light.server.LoadPageMojo.java
public void parsePageFile(final String filePath) { System.out.println("Process file = " + filePath); StringBuilder content = new StringBuilder(); try {//from www. j av a2 s .c om File file = new File(filePath); String id = getFileName(file); if (".html".equals(getExtension(file))) { final Scanner scan = new Scanner(file, encoding); String line = scan.nextLine(); while (scan.hasNext()) { content.append(line); content.append("\n"); line = scan.nextLine(); } content.append(line); content.append("\n"); // only import if content has been changed after comparing with server if (!content.toString().equals(pageMap.get(id))) { impPage(id, content.toString()); // generate SQL insert statements String sql = "INSERT INTO PAGE(id, content) VALUES ('" + id + "', '" + content.toString().replaceAll("'", "''") + "');\n"; sqlString += sql; } } } catch (final IOException e) { getLog().error(e.getMessage()); } }