Example usage for java.util Scanner next

List of usage examples for java.util Scanner next

Introduction

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

Prototype

public String next() 

Source Link

Document

Finds and returns the next complete token from this scanner.

Usage

From source file:com.marklogic.client.functionaltest.BasicJavaClientREST.java

/**
 * Write document using StringHandle//  w  w w.j  av a  2s  . c  o  m
 * @param client
 * @param filename
 * @param uri
 * @param type
 * @throws IOException
 */
public void writeDocumentUsingStringHandle(DatabaseClient client, String filename, String uri, String type)
        throws IOException {
    // acquire the content
    File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename);
    FileInputStream fis = new FileInputStream(file);
    Scanner scanner = new Scanner(fis).useDelimiter("\\Z");
    String readContent = scanner.next();
    fis.close();
    scanner.close();

    // create doc manager
    DocumentManager docMgr = null;
    docMgr = documentManagerSelector(client, docMgr, type);

    String docId = uri + filename;

    // create handle
    StringHandle contentHandle = new StringHandle();
    contentHandle.set(readContent);

    // write the doc
    docMgr.write(docId, contentHandle);

    System.out.println("Write " + docId + " to the database");
}

From source file:com.marklogic.client.functionaltest.BasicJavaClientREST.java

/**
 * Update document using FileHandle//w  w  w  .ja  va2 s.  c  om
 * @param client
 * @param filename
 * @param uri
 * @param type
 * @throws IOException
 */
public void updateDocumentUsingStringHandle(DatabaseClient client, String filename, String uri, String type)
        throws IOException {
    // create doc manager
    DocumentManager docMgr = null;
    docMgr = documentManagerSelector(client, docMgr, type);

    File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename);
    FileInputStream fis = new FileInputStream(file);
    Scanner scanner = new Scanner(fis).useDelimiter("\\Z");
    String readContent = scanner.next();
    fis.close();
    scanner.close();

    // create an identifier for the document
    String docId = uri;

    // create a handle on the content
    // create handle
    StringHandle contentHandle = new StringHandle();
    contentHandle.set(readContent);

    // write the document content
    docMgr.write(docId, contentHandle);

    System.out.println("Update " + docId + " to database");
}

From source file:io.realm.Realm.java

/**
 * Tries to update an existing object defined by its primary key with new JSON data. If no existing object could be
 * found a new object will be saved in the Realm. This must happen within a transaction.
 *
 * @param clazz Type of {@link io.realm.RealmObject} to create or update. It must have a primary key defined.
 * @param in    {@link InputStream} with object data in JSON format.
 * @return Created or updated {@link io.realm.RealmObject}.
 * @throws java.lang.IllegalArgumentException if trying to update a class without a
 * {@link io.realm.annotations.PrimaryKey}.
 * @see #createObjectFromJson(Class, java.io.InputStream)
 *//* w  w  w.  j a v a2s  .  co  m*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public <E extends RealmObject> E createOrUpdateObjectFromJson(Class<E> clazz, InputStream in)
        throws IOException {
    if (clazz == null || in == null) {
        return null;
    }
    checkHasPrimaryKey(clazz);

    // As we need the primary key value we have to first parse the entire input stream as in the general
    // case that value might be the last property :(
    Scanner scanner = null;
    try {
        scanner = getFullStringScanner(in);
        JSONObject json = new JSONObject(scanner.next());
        return configuration.getSchemaMediator().createOrUpdateUsingJsonObject(clazz, this, json, true);
    } catch (JSONException e) {
        throw new RealmException("Failed to read JSON", e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:io.realm.Realm.java

/**
 * Tries to update a list of existing objects identified by their primary key with new JSON data. If an existing
 * object could not be found in the Realm, a new object will be created. This must happen within a transaction.
 *
 * @param clazz Type of {@link io.realm.RealmObject} to create or update. It must have a primary key defined.
 * @param in    InputStream with a list of object data in JSON format.
 *
 * @throws java.lang.IllegalArgumentException if trying to update a class without a
 * {@link io.realm.annotations.PrimaryKey}.
 * @see #createOrUpdateAllFromJson(Class, java.io.InputStream)
 *///w  w  w .j  a  v  a2  s  . c o  m
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public <E extends RealmObject> void createOrUpdateAllFromJson(Class<E> clazz, InputStream in)
        throws IOException {
    if (clazz == null || in == null) {
        return;
    }
    checkHasPrimaryKey(clazz);

    // As we need the primary key value we have to first parse the entire input stream as in the general
    // case that value might be the last property :(
    Scanner scanner = null;
    try {
        scanner = getFullStringScanner(in);
        JSONArray json = new JSONArray(scanner.next());
        for (int i = 0; i < json.length(); i++) {
            configuration.getSchemaMediator().createOrUpdateUsingJsonObject(clazz, this, json.getJSONObject(i),
                    true);
        }
    } catch (JSONException e) {
        throw new RealmException("Failed to read JSON", e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:org.anurag.file.quest.FileQuestHD.java

/**
 * this function checks for update for File Quest
 * and makes a notification to download link
 * in playstore.... //from  w ww. jav  a2  s .com
 */
private void update_checker() {
    // TODO Auto-generated method stub
    Toast.makeText(FileQuestHD.this, R.string.checking_update, Toast.LENGTH_SHORT).show();

    final Handler hand = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {
            case 1://update available....
            {
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(FileQuestHD.this);
                mBuilder.setSmallIcon(R.drawable.file_quest_icon);
                mBuilder.setContentTitle(getString(R.string.app_name));
                mBuilder.setContentText(getString(R.string.update_avail));

                mBuilder.setTicker(getString(R.string.update_avail));

                Toast.makeText(FileQuestHD.this, R.string.update_avail, Toast.LENGTH_SHORT).show();

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=org.anurag.file.quest"));

                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                PendingIntent pendint = PendingIntent.getActivity(FileQuestHD.this, 900, intent, 0);
                mBuilder.setContentIntent(pendint);

                mBuilder.setAutoCancel(true);

                NotificationManager notimgr = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                notimgr.notify(1, mBuilder.build());
            }
                break;
            case 2://no connectivity....
                Toast.makeText(FileQuestHD.this, R.string.nointernet, Toast.LENGTH_SHORT).show();
                break;
            case 3:
                //failed to check for update....
                Toast.makeText(FileQuestHD.this, R.string.failed_to_check_for_update, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };

    Thread th = new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo info = cm.getActiveNetworkInfo();
                if (!info.isConnected()) {
                    hand.sendEmptyMessage(2);
                    return;
                }
                Scanner scan = new Scanner(
                        new URL("https://www.dropbox.com/s/x1gp7a6ozdvg81g/FQ_UPDATE.txt?dl=1").openStream());
                String update = scan.next();
                if (!update.equalsIgnoreCase(getString(R.string.version)))
                    hand.sendEmptyMessage(1);
                scan.close();
            } catch (Exception e) {
                hand.sendEmptyMessage(3);
            }
        }
    });
    th.start();
}

From source file:com.flexive.core.storage.genericSQL.GenericTreeStorage.java

/**
 * {@inheritDoc}/*from   w  w  w  .  j  a  v  a2 s . com*/
 */
@Override
public long[] createNodes(Connection con, SequencerEngine seq, ContentEngine ce, FxTreeMode mode,
        long parentNodeId, String path, int position, boolean activateContent) throws FxApplicationException {
    if ("/".equals(path))
        return new long[] { FxTreeNode.ROOT_NODE };
    final List<Long> result = new ArrayList<Long>();
    final Scanner scanner = new Scanner(path);
    long currentParent = parentNodeId;
    scanner.useDelimiter("/");
    if (parentNodeId != -1) {
        acquireLocksForUpdate(con, getTreeNodeInfo(con, mode, parentNodeId), false);
    }
    while (scanner.hasNext()) {
        String name = scanner.next();
        final FxString label = new FxString(true, name);
        name = FxFormatUtils.escapeTreePath(name);
        if (StringUtils.isEmpty(name))
            continue;
        long nodeId = getIdByFQNPath(con, mode, currentParent, "/" + name);
        if (nodeId == -1)
            nodeId = createNode(con, seq, ce, mode, nodeId, currentParent, name, label, position, null, null,
                    activateContent);
        result.add(nodeId);
        currentParent = nodeId;
    }
    return ArrayUtils.toPrimitive(result.toArray(new Long[result.size()]));
}

From source file:ehospital.Principal.java

private void btn_cargar_ambuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_ambuMouseClicked
    // TODO add your handling code here:
    Scanner sc = null;
    File archivo2;/* www  .  j a  v  a2s  .  c  o  m*/
    try {
        archivo2 = new File("./Ambulancia.txt");
        sc = new Scanner(archivo2);
        sc.useDelimiter(",");
        while (sc.hasNext()) {
            Ambulancias ambu = new Ambulancias(sc.next(), sc.nextInt(), sc.nextInt(), new Lugar(sc.next()),
                    sc.nextBoolean());
            lista_ambu.add(ambu);
        }
        JOptionPane.showMessageDialog(null, "Ambulancias Cargadas");
    } catch (Exception e) {
    } finally {
        sc.close();
    }
    System.out.println(lista_ambu.toString());
}

From source file:ehospital.Principal.java

private void btn_cargar_paramMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_paramMouseClicked
    // TODO add your handling code here:
    Scanner sc = null;
    File archivo2;//www.  j a va2s.  c  o m
    try {
        archivo2 = new File("./Paramedicos.txt");
        sc = new Scanner(archivo2);
        sc.useDelimiter(",");
        while (sc.hasNext()) {
            Paramedicos param = new Paramedicos(sc.next(), sc.nextInt(), sc.nextInt(), sc.next(),
                    new Lugar(sc.next()), sc.nextBoolean());
            lista_param.add(param);
        }
        JOptionPane.showMessageDialog(null, "Paramedicos Cargadas");
    } catch (Exception e) {
    } finally {
        sc.close();
    }
    System.out.println(lista_param.toString());
}

From source file:com.novartis.opensource.yada.test.ServiceTest.java

/**
 * Loads the resource at {@code path} containing query parameter or json
 * strings//  ww  w .  ja v a  2s  . c om
 * 
 * @param path the path to the test script
 * @return an array of query or json strings
 * @throws URISyntaxException when a handle can't be attached to the test file
 *         path
 * @throws IOException if the {@link InputStream} used for reading test files
 *         can't be closed
 */
@SuppressWarnings("resource")
public String[] loadResource(String path) throws URISyntaxException, IOException {
    Scanner scanner = null;
    String[] queries = null;
    java.net.URL resource = getClass().getResource(path);
    InputStream in = null;
    try {
        scanner = new Scanner(new File(resource.toURI()), UTF8);
    } catch (Exception e) {
        in = getClass().getResourceAsStream(path);
        if (in != null) {
            scanner = new Scanner(in, UTF8);
        }
    }

    if (scanner != null) {
        scanner.useDelimiter("\\Z");
        queries = scanner.next().split("\\n");
        scanner.close();
    }

    if (in != null)
        in.close();

    return queries;
}

From source file:net.emotivecloud.scheduler.drp4one.DRP4OVF.java

private String VMDescriptionNetwork(EmotiveOVF ovf) {

    StringBuilder buf = new StringBuilder();
    String tmp;//  w  w w .j  av  a 2s.  c o m

    // check for network attributes, if not available check the properties
    // file

    System.out.println("DRP4ONE - VMDescriptionNetwork()> ovf.getNetworks(): " + ovf.getNetworks());

    if (!ovf.getNetworks().isEmpty()) {

        //            added by smendoza
        //            String netSection = String.format("NIC = [ NETWORK_ID = %s ] \n",props.getProperty("net.id"));
        //            buf.append(netSection);

        // Network attributes
        netConnectNames = ovf4oneProperties(NET_CONNECTION_NAMES, false);
        for (OVFNetwork ovfNetwork : ovf.getNetworks().values()) {
            buf.append("NIC = [\n");
            String nicName = ovfNetwork.getConnectionName();

            // I am working on a new array, so I need to reset the separator
            String separator = "";

            if (nicName == null || "".equals(nicName)) {
                // We supply IP and MAC for this NIC
                tmp = ovfNetwork.getIp();
                if (tmp != null) {
                    buf.append("IP = \"");
                    buf.append(tmp);
                    buf.append("\"");
                    separator = ",\n";
                }

                tmp = ovfNetwork.getMac();
                if (tmp != null) {
                    buf.append(separator);
                    buf.append("MAC = \"");
                    buf.append(tmp);
                    buf.append("\"");
                }

            } else {
                // We ask OpenNebula to assign us IP and MAC
                System.out.println("DRP4ONE - VMDescriptionNetwork()> nicName: " + nicName);

                buf.append("NETWORK = \"");
                buf.append(nicName);
                buf.append("\" ");
            }
            buf.append("\n");
            nicNames.add(nicName);
            buf.append("]\n");
            System.out.println("DRP4ONE - VMDescriptionNetwork()> buf: " + buf);

            nicName = "";

        }

        log.debug("adding the networks configured in props..");
        log.debug("networks configured:" + netConnectNames);
        Scanner commaSperated = new Scanner(netConnectNames);
        commaSperated.useDelimiter(",");

        while (commaSperated.hasNext()) {
            String connectionName = commaSperated.next().trim();
            log.debug("connection name " + connectionName);
            Iterator<String> nicNamesIter = nicNames.iterator();
            while (nicNamesIter.hasNext()) {
                log.debug("nic names config in input:" + nicNamesIter.next());
            }
            if (!nicNames.contains(connectionName)) {
                //addNic(buf, connectionName);
            }
        }
    } else {
        log.debug("no network configured in ovf input, hence checking the network config from properties file");
        log.debug("networks configured:" + netConnectNames);
        Scanner commaSperated = new Scanner(netConnectNames);
        commaSperated.useDelimiter(",");

        while (commaSperated.hasNext()) {
            String connectionName = commaSperated.next().trim();
            // addNic(buf, connectionName);
            // buf.append("NIC = [\n");buf.append("NETWORK = \"");
            // buf.append(connectionName); buf.append("\"");
            // buf.append("]\n\n\n");
        }
    }

    return buf.toString();
}