List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:ca.weblite.xmlvm.VtableHelper.java
/** * Tries to find the actual function to use for the given mangled method name in the * given header file./* w w w.j av a 2 s . c o m*/ * @param searchPaths The paths to search for headers. * @param headerFile The header file in which to start the search. Its name is used * as the base for the mangled function name. * @param mangledMethodName The mangled method name. This should only be the portion * pertaining to the method - not the class portion of a mangled function name. It will * be concatenated to headerFile.getName()+"_" to form the full function name. * @return Either a VTable ID (which will have the form XMLVM_VTABLE_IDX_{funcname}) or * the actual function name if there is no vtable index constant defined. * @throws IOException */ public static String resolveVirtualMethod(Project project, Path searchPaths, File headerFile, String mangledMethodName) throws IOException { String mangledClassName = headerFile.getName().replaceAll("\\.h$", ""); String funcName = mangledClassName + "_" + mangledMethodName; String headerContents = FileUtils.readFileToString(headerFile); Scanner scanner = new Scanner(headerContents); int state = 0; String superClassHeader = null; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (state == 0 && line.startsWith("// Super Class:")) { state = 1; } else if (state == 1 && line.startsWith("#include \"")) { superClassHeader = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); state = 0; break; } } String idxConstant = "XMLVM_VTABLE_IDX_" + funcName; String idxConstantSp = idxConstant + " "; if (headerContents.indexOf(idxConstantSp) > 0) { return idxConstant; } else if (headerContents.indexOf(funcName + "(") > 0) { return funcName; } else if (superClassHeader != null) { for (String p : searchPaths.list()) { File d = new File(p); File h = new File(d, superClassHeader); if (h.exists()) { return resolveVirtualMethod(project, searchPaths, h, mangledMethodName); } } throw new RuntimeException("Failed to find header file " + superClassHeader); } else { throw new RuntimeException( "Failed to find virtual method " + mangledMethodName + " in header " + headerFile); } }
From source file:com.easarrive.aws.plugins.common.util.SNSUtil.java
public static StringBuilder getHttpRequestContent(InputStream inputStream) { Scanner scan = null; StringBuilder builder = new StringBuilder(); try {//from ww w.jav a2 s .c o m scan = new Scanner(inputStream); while (scan.hasNextLine()) { builder.append(scan.nextLine()); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtil.close(scan); } return builder; }
From source file:css.variable.converter.CSSVariableConverter.java
/** * Go through existing CSS Files and replace variable access with variable * values//from w w w . j av a 2s .c o m * * @param rootCSSVars All css variables you want to convert from name to value */ private static void editForRelease(ArrayList<CSSVar> rootCSSVars) { for (File cssFile : theCSSList) { ArrayList<CSSVar> localCSSVars = getCSSVars(cssFile, ":local"); for (CSSVar cssVar : rootCSSVars) { if (!localCSSVars.contains(cssVar)) { localCSSVars.add((CSSVar) (cssVar.clone())); } } // This will store info the new text for the file we will write below ArrayList<String> filesNewInfo = new ArrayList<String>(); try { Scanner fileReader = new Scanner(cssFile); while (fileReader.hasNextLine()) { String currentLine = fileReader.nextLine(); // If we find variables, replace them, with their value if (currentLine.contains("var(")) { for (CSSVar var : localCSSVars) { while (currentLine.contains(var.getName())) { currentLine = currentLine.replace("var(" + var.getName() + ")", var.getValue()); } } } // Add new currentLine to be written filesNewInfo.add(currentLine); } fileReader.close(); } catch (FileNotFoundException ex) { Logger.getLogger(CSSVariableConverter.class.getName()).log(Level.SEVERE, null, ex); } // Write the new files below try { BufferedWriter writer = new BufferedWriter(new FileWriter(cssFile.getPath())); while (!filesNewInfo.isEmpty()) { writer.write(filesNewInfo.get(0)); writer.newLine(); filesNewInfo.remove(0); } writer.close(); } catch (IOException ex) { Logger.getLogger(CSSVariableConverter.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.mirth.connect.server.util.DatabaseUtil.java
public static List<String> joinSqlStatements(Collection<String> scripts) { List<String> scriptList = new ArrayList<String>(); for (String script : scripts) { script = script.trim();/*from w ww . ja v a 2 s . c om*/ StringBuilder sb = new StringBuilder(); boolean blankLine = false; Scanner scanner = new Scanner(script); while (scanner.hasNextLine()) { String temp = scanner.nextLine(); if (temp.trim().length() > 0) { sb.append(temp + " "); } else { blankLine = true; } if (blankLine || !scanner.hasNextLine()) { scriptList.add(sb.toString().trim()); blankLine = false; sb.delete(0, sb.length()); } } } return scriptList; }
From source file:io.github.felsenhower.stine_calendar_bot.main.CallLevelWrapper.java
/** * Gets the password from stdin/*from w w w .ja v a 2 s . c om*/ * * @param query * the query to the user * @param errorMsg * the message to display when the input gets somehow redirected * and System.console() becomes null. * @return the entered password */ private static String readPassword(String query, String errorMsg) { final String result; if (System.console() != null) { System.err.print(query); result = new String(System.console().readPassword()); } else { System.err.println(errorMsg); System.err.print(query); Scanner scanner = new Scanner(System.in); result = scanner.nextLine(); scanner.close(); } System.err.println(); return result; }
From source file:at.tuwien.aic.Main.java
private static String getNonEmptyString(String msg, String defaultValue) { Scanner scanner = new Scanner(System.in); String ret = defaultValue;//from www . j a va 2 s. c o m print(msg, ret); while (scanner.hasNextLine()) { ret = scanner.nextLine(); if (!ret.equals("")) { break; } print(msg, ret); } return ret; }
From source file:com.vmware.fdmsecprotomgmt.PasswdEncrypter.java
/** * Decrypt the original password by using the secretKey and encrypted string *//* w ww. j av a 2s. c o m*/ public static List<String> decryptValueWithUserEnteredKey(String encryptedStr) { boolean validVals = false; String secretKey = ""; List<String> decryptedStrList = null; try { Scanner in = new Scanner(System.in); System.out.print( "For decrypting ESXi password, Please Enter SecretKey (16 characters) that was used earlier: "); secretKey = in.nextLine().trim(); if (secretKey.length() == STD_KEYSIZE) { validVals = true; } else { System.out.println("Invalid secretKey, please try again"); } // reset the scanner in.reset(); // Go for encrypting the password with provided SecretKey if (validVals) { if ((!encryptedStr.equals(""))) { // Validate that on decrypt, you would receive the same // password String tempDecryptedStr = decrypt(secretKey, encryptedStr); if (!tempDecryptedStr.equals("")) { System.out.println( "Successfully decrypted ESXi password with provided secretKey: " + secretKey); decryptedStrList = new ArrayList<String>(); decryptedStrList.add(secretKey); decryptedStrList.add(tempDecryptedStr); } else { System.err.println("Failed to decrypt the encrypted string: " + encryptedStr + ", with provided secretkey: " + secretKey); System.err.println( "Please review the secretkey provided. It has to be the same as the one provided during" + " encrypted the original password"); } } else { System.err.println("Encrypted Value provided is empty/null"); } } } catch (Exception e) { System.err.println("Caught exception while decrypting ESXi password"); decryptedStrList = null; } return decryptedStrList; }
From source file:ec.edu.ucuenca.dcc.sld.HttpUtils.java
public static synchronized String Http2_(String s, Map<String, String> mp) throws SQLException, IOException { String resp = ""; 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()); }// ww w . j a v a2 s .com 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(); } return resp; }
From source file:tr.edu.gsu.nerwip.tools.corpus.ArticleCompletion.java
/** * This methods allows setting the category of * articles already retrieved and manually annotated * for evaluation. This way, the annotation can be * performed overall, or in function of the category. * The categories must be listed in a file in which * each line contains the name of the article folder * and the corresponding category./* w ww. ja v a 2 s . co m*/ * * @throws ParseException * Problem while accessing the files. * @throws SAXException * Problem while accessing the files. * @throws IOException * Problem while accessing the files. */ private static void insertArticleCategories() throws ParseException, SAXException, IOException { logger.log("Setting categories in articles"); logger.increaseOffset(); File file = new File(FileNames.FO_OUTPUT + File.separator + "cats" + FileNames.EX_TXT); FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); Scanner scanner = new Scanner(isr); logger.log("Reading file " + file); logger.increaseOffset(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String temp[] = line.split("\\t"); String name = temp[0]; String folderPath = FileNames.FO_OUTPUT + File.separator + name; File folderFile = new File(folderPath); if (folderFile.exists()) { // String gender = temp[1]; String categoryStr = temp[2].toUpperCase(Locale.ENGLISH); ArticleCategory category = ArticleCategory.valueOf(categoryStr); //category = StringTools.initialize(category); logger.log("Processing '" + name + "': cat=" + category); List<ArticleCategory> categories = new ArrayList<ArticleCategory>(); categories.add(category); Article article = Article.read(name); article.setCategories(categories); article.write(); } else logger.log("Processing '" + temp[0] + "': folder not found"); } logger.decreaseOffset(); scanner.close(); logger.decreaseOffset(); logger.log("Categories set"); }
From source file:ec.edu.ucuenca.dcc.sld.HttpUtils.java
public static synchronized String Http2(String s, Map<String, String> mp) throws SQLException, IOException { String resp = ""; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(s); method.getParams().setContentCharset("utf-8"); client.getParams().setParameter("api-key", "58ef39e0-b91a-11e6-a057-97f4c970893c"); client.getParams().setParameter("Content-Type", "application/json"); //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()); }// w w w. j a v a2s.c om 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(); } return resp; }