List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:com.cloudant.client.org.lightcouch.internal.CouchDbUtil.java
public static String streamToString(InputStream in) { Scanner s = new Scanner(in, "UTF-8"); s.useDelimiter("\\A"); String str = s.hasNext() ? s.next() : null; close(in);/*w ww.ja v a 2s .co m*/ s.close();// mdb return str; }
From source file:com.doplgangr.secrecy.Util.java
public static Map<String, java.io.File> getAllStorageLocations() { Map<String, java.io.File> map = new TreeMap<String, File>(); List<String> mMounts = new ArrayList<String>(99); //List<String> mVold = new ArrayList<String>(99); mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); try {//from w w w .j a v a 2 s . c o m java.io.File mountFile = new java.io.File("/proc/mounts"); if (mountFile.exists()) { Scanner scanner = new Scanner(mountFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("/dev/block/vold/")) { String[] lineElements = line.split(" "); String element = lineElements[1]; mMounts.add(element); } } } catch (Exception e) { e.printStackTrace(); } /** try { java.io.File voldFile = new java.io.File("/system/etc/vold.fstab"); if (voldFile.exists()) { Scanner scanner = new Scanner(voldFile); while (scanner.hasNext()) { String line = scanner.nextLine(); //if (line.startsWith("dev_mount")) { String[] lineElements = line.split(" "); String element = lineElements[2]; if (element.contains(":")) element = element.substring(0, element.indexOf(":")); mVold.add(element); } } } catch (Exception e) { e.printStackTrace(); } **/ /* for (int i = 0; i < mMounts.size(); i++) { String mount = mMounts.get(i); if (!mVold.contains(mount)) mMounts.remove(i--); } mVold.clear(); */ List<String> mountHash = new ArrayList<String>(99); for (String mount : mMounts) { java.io.File root = new java.io.File(mount); Util.log(mount, "is checked"); Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); if (canWrite(root)) { Util.log(mount, "is writable"); java.io.File[] list = root.listFiles(); String hash = "["; if (list != null) for (java.io.File f : list) hash += f.getName().hashCode() + ":" + f.length() + ", "; hash += "]"; if (!mountHash.contains(hash)) { String key = root.getAbsolutePath() + " (" + org.apache.commons.io.FileUtils.byteCountToDisplaySize(root.getUsableSpace()) + " free space)"; mountHash.add(hash); map.put(key, root); } } } mMounts.clear(); return map; }
From source file:org.my.eaptest.UploadServlet.java
private static String fromStream(InputStream is) { Scanner s = new Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:org.bibsonomy.rest.utils.HeaderUtils.java
/** * //from w w w . ja v a2s .c o m * @param acceptHeader * the HTML ACCEPT Header * <br/>example: * <code>ACCEPT: text/xml,text/html;q=0.9,text/plain;q=0.8,image/png</code> * would be interpreted in the following precedence: * <ol> * <li>text/xml</li> * <li>image/png</li> * <li>text/html</li> * <li>text/plain</li> * </ol> * ) * @return a sorted map with the precedences */ public static SortedMap<Double, Vector<String>> getPreferredTypes(final String acceptHeader) { // maps the q-value to output format (reverse order) final SortedMap<Double, Vector<String>> preferredTypes = new TreeMap<Double, Vector<String>>( new Comparator<Double>() { @Override public int compare(Double o1, Double o2) { if (o1.doubleValue() > o2.doubleValue()) return -1; else if (o1.doubleValue() < o2.doubleValue()) return 1; else return o1.hashCode() - o2.hashCode(); } }); if (!present(acceptHeader)) { return preferredTypes; } // fill map with q-values and formats final Scanner scanner = new Scanner(acceptHeader.toLowerCase()); scanner.useDelimiter(","); while (scanner.hasNext()) { final String[] types = scanner.next().split(";"); final String type = types[0]; double qValue = 1; if (types.length != 1) { /* * FIXME: we get * java.lang.NumberFormatException: For input string: "screen" * in the error log because the format we assume seems to be * different by some clients. Until we find out, what is really * wrong (our parsing or the client), we are more careful with * parsing external data. */ try { qValue = Double.parseDouble(types[1].split("=")[1]); } catch (NumberFormatException e) { qValue = 0; log.error("Couldn't parse accept header '" + acceptHeader + "'"); } } Vector<String> v = preferredTypes.get(qValue); if (!preferredTypes.containsKey(qValue)) { v = new Vector<String>(); preferredTypes.put(qValue, v); } v.add(type); } return preferredTypes; }
From source file:com.sample.ecommerce.util.ElasticSearchUtil.java
public static String getContentFromClasspath(String resourcePath) { InputStream inputStream = ElasticSearchUtil.class.getResourceAsStream(resourcePath); java.util.Scanner scanner = new java.util.Scanner(inputStream, "UTF-8").useDelimiter("\\A"); String theString = scanner.hasNext() ? scanner.next() : ""; scanner.close();//from w ww. j a v a 2 s .c o m return theString; }
From source file:com.almende.pi5.lch.SimManager.java
private static String convertStreamToString(InputStream is) { final Scanner s = new Scanner(is, "UTF-8"); s.useDelimiter("\\A"); final String result = s.hasNext() ? s.next() : ""; s.close();/*from w ww . j ava 2 s . c o m*/ return result; }
From source file:main.Draft_text_categorization.java
/** * Devuelve un Set<String> compuesto por los trminos * que aparecen en el archivo txt pasado como parmetro * /*w ww. j av a 2 s. co m*/ * @param file * @return */ public static Set<String> fileToSet(Scanner file) { Set<String> doc = new HashSet<>(); while (file.hasNext()) { doc.add(file.next().trim().toLowerCase()); } return doc; }
From source file:nz.org.winters.appspot.acrareporter.server.MappingUploadHandler.java
public static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is); s.useDelimiter("\\A"); try {/* ww w. ja va 2 s.c o m*/ return s.hasNext() ? s.next() : ""; } finally { s.close(); } }
From source file:driimerfinance.helpers.FinanceHelper.java
/** * Checks if the license is valid using the License Key Server * * @param license key to check//w w w . ja va 2s . com * @return validity of the license (true or false) */ public static boolean checkLicense(String licenseKey) { HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost("http://driimerfinance.michaelkohler.info/checkLicense"); List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("key", licenseKey)); // pass the key to the server try { httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (UnsupportedEncodingException e) { return false; } HttpResponse response = null; try { response = httpclient.execute(httppost); // get the response from the server } catch (IOException e) { return false; } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); @SuppressWarnings("resource") java.util.Scanner s = new java.util.Scanner(instream).useDelimiter("\\A"); // parse the response String responseString = s.hasNext() ? s.next() : ""; instream.close(); return responseString.contains("\"valid\":true"); // if the license is valid, return true, else false } catch (IllegalStateException | IOException e) { return false; } } return false; }
From source file:org.t3.metamediamanager.OmdbProvider.java
/** * Converts an InputStream object into a String object. * @param is// ww w .jav a2 s . c o m * The InputStream you want to convert. * @return * A String Object. */ private static String convertStreamToString(InputStream is) { Scanner s = new Scanner(is); Scanner s2 = s.useDelimiter("\\A"); String res = s.hasNext() ? s.next() : ""; s2.close(); s.close(); return res; }