List of usage examples for java.util Scanner next
public String next()
From source file:com.dropbox.client2.RESTUtility.java
/** * Reads in content from an {@link HttpResponse} and parses it as a query * string.//from w w w . ja v a 2s . c om * * @param response the {@link HttpResponse}. * * @return a map of parameter names to values from the query string. * * @throws DropboxIOException if any network-related error occurs while * reading in content from the {@link HttpResponse}. * @throws DropboxParseException if a malformed or unknown response was * received from the server. * @throws DropboxException for any other unknown errors. This is also a * superclass of all other Dropbox exceptions, so you may want to * only catch this exception which signals that some kind of error * occurred. */ public static Map<String, String> parseAsQueryString(HttpResponse response) throws DropboxException { HttpEntity entity = response.getEntity(); if (entity == null) { throw new DropboxParseException("Bad response from Dropbox."); } Scanner scanner; try { scanner = new Scanner(entity.getContent()).useDelimiter("&"); } catch (IOException e) { throw new DropboxIOException(e); } Map<String, String> result = new HashMap<String, String>(); while (scanner.hasNext()) { String nameValue = scanner.next(); String[] parts = nameValue.split("="); if (parts.length != 2) { throw new DropboxParseException("Bad query string from Dropbox."); } result.put(parts[0], parts[1]); } return result; }
From source file:com.ckfinder.connector.utils.FileUtils.java
/** * checks is file extension is on denied list or isn't on allowed list. * @param fileExt file extension/*from ww w . java2s. co m*/ * @param type file resource type * @return 0 if isn't on denied and is on allowed, otherwise 1 */ private static boolean checkSingleExtension(final String fileExt, final ResourceType type) { Scanner scanner = new Scanner(type.getDeniedExtensions()).useDelimiter(","); while (scanner.hasNext()) { if (scanner.next().equalsIgnoreCase(fileExt)) { return false; } } Scanner scanner1 = new Scanner(type.getAllowedExtensions()).useDelimiter(","); while (scanner1.hasNext()) { if (scanner1.next().equalsIgnoreCase(fileExt)) { return true; } } return false; }
From source file:org.kalypso.kalypsomodel1d2d.conv.SWANDataConverterHelper.java
public static GM_Position readCoordinateShiftValues(final FileObject pFile) { GM_Position lPosRes = null;// w ww.j a v a2 s .c o m Scanner scannerFile = null; Scanner scannerLine = null; try { FileObject swanShiftCoordFileObject = pFile.getParent() .getChild(ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_FILE); if (swanShiftCoordFileObject == null) { return lPosRes; } File lFile = new File(swanShiftCoordFileObject.getURL().toURI()); scannerFile = new Scanner(lFile); Double lDoubleShiftY = null; Double lDoubleShiftX = null; while (scannerFile.hasNextLine()) { String lStrNextLine = scannerFile.nextLine(); if (lStrNextLine.contains("=")) { //$NON-NLS-1$ scannerLine = new Scanner(lStrNextLine); scannerLine.useDelimiter("="); //$NON-NLS-1$ String lStrValueName = scannerLine.next(); String lStrValue = scannerLine.next(); if (ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_X.equalsIgnoreCase(lStrValueName)) { lDoubleShiftX = Double.parseDouble(lStrValue); } else if (ISimulation1D2DConstants.SIM_SWAN_COORD_SHIFT_Y.equalsIgnoreCase(lStrValueName)) { lDoubleShiftY = Double.parseDouble(lStrValue); } scannerLine.close(); } else { // System.out.println("Empty or invalid line. Unable to process. Processing the results without shift!"); } } if (lDoubleShiftX != null && lDoubleShiftY != null) lPosRes = GeometryFactory.createGM_Position(lDoubleShiftX, lDoubleShiftY); } catch (Exception e) { e.printStackTrace(); } finally { if (scannerFile != null) scannerFile.close(); if (scannerLine != null) scannerLine.close(); } return lPosRes; }
From source file:com.tesora.dve.tools.CLIBuilder.java
protected static String scanFilePath(Scanner scanner) { if (scanner.hasNext()) { final String token = scanner.next(); if (token.startsWith("\"") || token.startsWith("'")) { final String quote = String.valueOf(token.charAt(0)); if (!token.endsWith(quote)) { final String remainder = scanner.findInLine(".+?" + quote); return token.substring(1) + remainder.substring(0, remainder.length() - 1); }// ww w . java 2s . c o m return token.substring(1, token.length() - 1); } return token; } return StringUtils.EMPTY; }
From source file:org.spring.data.gemfire.app.boot.SpringBootDataGemFireCacheClientApplication.java
@Override public void run(String... args) throws Exception { Scanner scanner = new Scanner(System.in); scanner.next(); }
From source file:ar.edu.taco.TacoMain.java
public static String editTestFileToCompile(String junitFile, String sourceClassName, String classPackage, String methodName) {//from w w w. ja v a2 s . c o m String tmpDir = junitFile.substring(0, junitFile.lastIndexOf(FILE_SEP)); tmpDir = tmpDir.replaceAll("generated", "output"); File destFile = new File(tmpDir, obtainClassNameFromFileName(junitFile) + /*"_temp" +*/ ".java"); String packageSentence = "package " + classPackage + ";\n"; int posLastUnderscore = methodName.lastIndexOf("_"); methodName = methodName.substring(0, posLastUnderscore); try { destFile.createNewFile(); FileOutputStream fos = new FileOutputStream(destFile); boolean packageAlreadyWritten = false; Scanner scan = new Scanner(new File(junitFile)); scan.useDelimiter("\n"); boolean nextToTest = false; String str = null; while (scan.hasNext()) { str = scan.next(); if (nextToTest) { str = str.replace("()", "(String fileClasspath, String className, String methodName) throws IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException, MalformedURLException"); fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); nextToTest = false; // } else if (str.contains("public class")){ // int posOpeningBrace = str.indexOf("{"); // str = str.substring(0, posOpeningBrace-1); // str = str + "_temp {"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("package") && !packageAlreadyWritten) { fos.write(packageSentence.getBytes(Charset.forName("UTF-8"))); str = " import java.net.URL;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " import java.net.URLClassLoader;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " import java.net.MalformedURLException;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " import java.io.File;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " import java.lang.reflect.InvocationTargetException;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); packageAlreadyWritten = true; } else if (str.contains("import") && !packageAlreadyWritten) { fos.write(packageSentence.getBytes(Charset.forName("UTF-8"))); fos.write((scan.next() + "\n").getBytes(Charset.forName("UTF-8"))); packageAlreadyWritten = true; } else if (str.contains("new " + sourceClassName + "(")) { // str = " try {"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " ClassLoader cl = ClassLoader.getSystemClassLoader();"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " ClassLoader cl2 = new URLClassLoader(new URL[]{new File(fileClasspath).toURI().toURL()}, cl);"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); // str = " ClassLoaderTools.addFile(fileClasspath);"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " Class<?> clazz = cl2.loadClass(className);"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " Object instance = clazz.newInstance();"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " cl2 = null;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("Class<?> clazz;")) { } else if (str.contains("} catch (ClassNotFoundException e) {")) { str = str.replace("ClassNotFoundException", "Exception"); fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.matches(".*(?i)[\\.a-z0-9\\_]*" + sourceClassName + "(?=[^a-z0-9\\_\\.]).*")) { str = str.replaceAll("(?i)[\\.a-z0-9\\_]*" + sourceClassName + "(?=[^a-z0-9\\_\\.])", /*classPackage+"."+*/sourceClassName); str = str.replace("\"" + methodName + "\"", "methodName"); str = str.replace("\"" + sourceClassName + "\"", "clazz"); // str = str.replace("(", "(fileClasspath, "); fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("e.printStackTrace();")) { // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); fos.write((" throw(new java.lang.RuntimeException(e));" + "\n") .getBytes(Charset.forName("UTF-8"))); // fos.write(("throw e;" + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("private Method getAccessibleMethod")) { str = str.replace("(String className, ", "(Class<?> clazz, "); // str = str.replace(") {", ") throws MalformedURLException {"); fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("method.invoke(instance,")) { fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " instance = null;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); str = " method = null;"; fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("methodToCheck = clazz.getDeclaredMethod(methodName, parameterTypes);")) { fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else if (str.contains("clazz = Class.forName(className);")) { // str = " ClassLoader cl = ClassLoader.getSystemClassLoader();"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); // str = " final ClassLoader cl2 = new URLClassLoader(new URL[]{new File(fileClasspath).toURI().toURL()}, cl);"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); // str = " clazz = cl2.loadClass(className);"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); // str = " System.out.println(\"actual class inside method: \"+clazz.getName());"; // fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } else { if (str.contains("@Test")) { nextToTest = true; } // if (!scan.hasNext()){ // String s = " } catch (ClassNotFoundException e){"; // fos.write((s + "\n").getBytes(Charset.forName("UTF-8"))); // s = " } catch (InstantiationException e){}"; // fos.write((s + "\n").getBytes(Charset.forName("UTF-8"))); // } fos.write((str + "\n").getBytes(Charset.forName("UTF-8"))); } } fos.close(); scan.close(); } catch (IOException e) { e.printStackTrace(); } return destFile.toString(); }
From source file:org.openbaton.vnfm.generic.GenericVNFM.java
private static String convertStreamToString(InputStream is) { Scanner s = new Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:instastats.InstaStats.java
private String getAccessCode() { String codePath = this.getClass().getResource("").getPath() + localCodePath; File codeFile = new File(codePath); String code = null;/* w ww . j av a 2s.co m*/ try { Scanner scanner = new Scanner(codeFile); code = scanner.next(); scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } return code; }
From source file:org.opencms.workplace.explorer.CmsExplorer.java
/** * Creates a link for the OpenCms workplace that will reload the whole workplace, switch to the explorer view, the * site of the given explorerRootPath and show the folder given in the explorerRootPath. * <p>// w w w . ja va 2s .c o m * * @param cms * the cms object * * @param explorerRootPath * a root relative folder link (has to end with '/'). * * @return a link for the OpenCms workplace that will reload the whole workplace, switch to the explorer view, the * site of the given explorerRootPath and show the folder given in the explorerRootPath. */ public static String getWorkplaceExplorerLink(final CmsObject cms, final String explorerRootPath) { // split the root site: StringBuffer siteRoot = new StringBuffer(); StringBuffer path = new StringBuffer('/'); Scanner scanner = new Scanner(explorerRootPath); scanner.useDelimiter("/"); int count = 0; while (scanner.hasNext()) { if (count < 2) { siteRoot.append('/').append(scanner.next()); } else { if (count == 2) { path.append('/'); } path.append(scanner.next()); path.append('/'); } count++; } String targetSiteRoot = siteRoot.toString(); String targetVfsFolder = path.toString(); // build the link StringBuilder link2Source = new StringBuilder(); link2Source.append("/system/workplace/views/workplace.jsp?"); link2Source.append(CmsWorkplace.PARAM_WP_EXPLORER_RESOURCE); link2Source.append("="); link2Source.append(targetVfsFolder); link2Source.append("&"); link2Source.append(CmsFrameset.PARAM_WP_VIEW); link2Source.append("="); link2Source.append(OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms, "/system/workplace/views/explorer/explorer_fs.jsp")); link2Source.append("&"); link2Source.append(CmsWorkplace.PARAM_WP_SITE); link2Source.append("="); link2Source.append(targetSiteRoot); String result = link2Source.toString(); result = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms, result); return result; }
From source file:com.lithium.flow.filer.hash.ClientHashFiler.java
@Override @Nonnull//from www. j a va2 s . c o m public String getHash(@Nonnull String path, @Nonnull String hash, @Nonnull String base) throws IOException { return client.call("hash " + path, input -> { Scanner scanner = new Scanner(input); scanner.next(); // size String value = scanner.next(); scanner.next(); // status return BaseEncodings.of(base).encode(encoding.decode(value)); }); }