Example usage for java.util Scanner hasNext

List of usage examples for java.util Scanner hasNext

Introduction

In this page you can find the example usage for java.util Scanner hasNext.

Prototype

public boolean hasNext() 

Source Link

Document

Returns true if this scanner has another token in its input.

Usage

From source file:com.mirth.connect.client.ui.components.rsta.ac.js.PartialHashMap.java

private String[] splitKey(String key) {
    List<String> list = new ArrayList<String>();

    Scanner scanner = new Scanner(key);
    scanner.useDelimiter(SPLIT_PATTERN);
    while (scanner.hasNext()) {
        list.add(scanner.next().toLowerCase());
    }/*from w w w .j  av  a  2  s .  c  o m*/
    scanner.close();

    return list.toArray(new String[list.size()]);
}

From source file:org.apache.streams.datasift.example.DatasiftWebhookResource.java

@POST
@Path("json_new_line")
public Response datasift_json_new_line(@Context HttpHeaders headers, String body) {

    //log.debug(headers.toString(), headers);

    //log.debug(body.toString(), body);

    ObjectNode response = mapper.createObjectNode();

    if (body.equalsIgnoreCase("{}")) {

        Boolean success = true;//from  w  w w.  j a v  a 2  s.co m

        response.put("success", success);

        return Response.status(200).entity(response).build();
    }

    try {

        Scanner scanner = new Scanner(body);

        while (scanner.hasNext()) {
            String item = scanner.next();

            StreamsDatum datum = new StreamsDatum(item);

            lock.writeLock().lock();
            ComponentUtils.offerUntilSuccess(datum, providerQueue);
            lock.writeLock().unlock();

        }

        log.info("interactionQueue: " + providerQueue.size());

        Boolean success = true;

        response.put("success", success);

        return Response.status(200).entity(response).build();

    } catch (Exception e) {
        log.warn(e.toString(), e);
    }

    return Response.status(500).build();
}

From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java

/**
 * Checks whether files extension is allowed.
 *
 * @param fileExt a string representing file extension to test
 * @param type a {@code ResourceType} object holding list of allowed and denied extensions against which parameter fileExt will be
 * tested//from w  w  w  .  jav a2 s  . c  o m
 * @return {@code true} is extension is on allowed extensions list or if allowed extensions is empty. The {@code false} is returned when
 * file is on denied extensions list or if none of the above conditions is met.
 */
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 = new Scanner(type.getAllowedExtensions()).useDelimiter(",");
    //The allowedExtensions is empty. Allow everything that isn't dissallowed.
    if (!scanner.hasNext()) {
        return true;
    }

    while (scanner.hasNext()) {
        if (scanner.next().equalsIgnoreCase(fileExt)) {
            return true;
        }
    }
    return false;
}

From source file:com.muzima.service.HTMLFormObservationCreatorTest.java

public String readFile() {
    InputStream fileStream = getClass().getClassLoader().getResourceAsStream("html/dispensary.json");
    Scanner s = new Scanner(fileStream).useDelimiter("\\A");
    return s.hasNext() ? s.next() : "{}";
}

From source file:com.github.woonsan.katharsis.invoker.KatharsisInvoker.java

private RequestBody inputStreamToBody(InputStream is) throws IOException {
    if (is == null) {
        return null;
    }//ww  w  .j a va 2  s. c  om

    Scanner s = new Scanner(is).useDelimiter("\\A");
    String requestBody = s.hasNext() ? s.next() : "";

    if (requestBody == null || requestBody.isEmpty()) {
        return null;
    }

    return objectMapper.readValue(requestBody, RequestBody.class);
}

From source file:org.neo4j.server.web.logging.HTTPLoggingFunctionalTest.java

private boolean occursIn(String lookFor, File file) throws FileNotFoundException {
    if (!file.exists()) {
        return false;
    }/*from w  ww  . ja  v a  2 s.  c o m*/

    boolean result = false;
    Scanner scanner = new Scanner(file);
    while (scanner.hasNext()) {
        if (scanner.next().contains(lookFor)) {
            result = true;
        }
    }

    scanner.close();

    return result;
}

From source file:ch.cyberduck.core.importer.S3BrowserBookmarkCollection.java

@Override
protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
    try {/*from  ww  w.j  a  v a2 s.c o m*/
        final BufferedReader in = new BufferedReader(
                new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
        try {
            Host current = null;
            String line;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("[account_")) {
                    current = new Host(protocols.forType(Protocol.Type.s3));
                } else if (StringUtils.isBlank(line)) {
                    this.add(current);
                    current = null;
                } else {
                    if (null == current) {
                        log.warn("Failed to detect start of bookmark");
                        continue;
                    }
                    Scanner scanner = new Scanner(line);
                    scanner.useDelimiter(" = ");
                    if (!scanner.hasNext()) {
                        log.warn("Missing key in line:" + line);
                        continue;
                    }
                    String name = scanner.next().toLowerCase(Locale.ROOT);
                    if (!scanner.hasNext()) {
                        log.warn("Missing value in line:" + line);
                        continue;
                    }
                    String value = scanner.next();
                    if ("name".equals(name)) {
                        current.setNickname(value);
                    } else if ("comment".equals(name)) {
                        current.setComment(value);
                    } else if ("access_key".equals(name)) {
                        current.getCredentials().setUsername(value);
                    } else if ("secret_key".equals(name)) {
                        current.getCredentials().setPassword(value);
                    }
                }
            }
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException e) {
        throw new AccessDeniedException(e.getMessage(), e);
    }
}

From source file:org.dbpedia.spotlight.io.DataLoader.java

public Map<String, Double> loadPriors(InputStream in) throws IOException {

    Map<String, Double> items = new HashMap<String, Double>();
    Scanner scanner = new Scanner(new InputStreamReader(in, "UTF-8"));
    int i = 0;/* ww w . j  a  va2 s.c o m*/
    while (scanner.hasNext()) {
        String line = scanner.nextLine();
        try {
            mParser.add(line.toString(), items);
            i++;

            in.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    LOG.info("Done. Loaded " + items.size() + " items.");

    return items;
}

From source file:by.bsu.zmiecer.PieChartDemo1.java

/**
 * Creates a sample dataset.//from   www . j a  v a2s  .  c  o m
 * 
 * Source: http://www.bbc.co.uk/news/business-15489523
 *
 * @return A sample dataset.
 */
private PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    try {

        File file = new File(
                "C:\\Users\\\\\\GitHub\\BSU\\2 course\\Practical Training\\Week 5\\Task53\\input.txt");
        Scanner sc = new Scanner(file);
        while (sc.hasNext()) {
            String name;
            if (sc.hasNext())
                name = sc.next();
            else
                throw new InputMismatchException();
            Double val;
            if (sc.hasNext()) {
                val = Double.valueOf(sc.next());
                if (val < 0)
                    throw new NumberFormatException();
            } else
                throw new InputMismatchException();
            dataset.setValue(name, val);
        }
    } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(getParent(), "File not found!");
    } catch (InputMismatchException e) {
        JOptionPane.showMessageDialog(getParent(), "Enter corret data!");
    } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(getParent(), "Enter corret data!");
    }
    return dataset;
}

From source file:org.catnut.service.UpgradeService.java

private void checkout() throws Exception {
    URL url = new URL(METADATA_URL);
    InputStream inputStream = url.openStream();
    Scanner in = new Scanner(inputStream).useDelimiter("\\A");
    if (in.hasNext()) {
        JSONObject metadata = new JSONObject(in.next());
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
        if (info.versionCode < metadata.optInt(FIELD_VERSION_CODE)) {
            Notification.InboxStyle style = new Notification.InboxStyle(mBuilder);
            String size = metadata.optString("size");
            style.setBigContentTitle(getString(R.string.find_new_version, size));
            JSONArray messages = metadata.optJSONArray("messages");
            for (int i = 0; i < messages.length(); i++) {
                style.addLine(messages.optString(i));
            }/*from   w w  w.  j a  va2s.  com*/
            // download&upgrade intent
            Intent download = new Intent(this, UpgradeService.class);
            download.setAction(ACTION_DOWNLOAD);
            download.putExtra(DOWNLOAD_LINK, metadata.optString(DOWNLOAD_LINK));
            PendingIntent piDownload = PendingIntent.getService(this, 0, download, 0);
            mBuilder.addAction(R.drawable.ic_stat_download_dark, getString(R.string.down_load_and_upgrade),
                    piDownload);
            // dismiss notification
            Intent dismiss = new Intent(this, UpgradeService.class);
            dismiss.setAction(ACTION_DISMISS);
            PendingIntent piDismiss = PendingIntent.getService(this, 0, dismiss, 0);
            mBuilder.addAction(R.drawable.ic_stat_content_remove_dark, getString(R.string.not_upgrade_now),
                    piDismiss);
            // show it.
            mBuilder.setTicker(getString(R.string.find_new_version));
            mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build());
        } else {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(UpgradeService.this, getString(R.string.already_updated), Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
    }
    in.close();
}