Example usage for java.util Scanner nextLong

List of usage examples for java.util Scanner nextLong

Introduction

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

Prototype

public long nextLong() 

Source Link

Document

Scans the next token of the input as a long .

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 true ";
    Long l = 123456789098765432L;
    s = s + l;/*www.jav  a2s  .  co m*/

    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {

        System.out.println("Not Found :" + scanner.next());

        if (scanner.hasNextLong()) {
            System.out.println("Found :" + scanner.nextLong());
        }
    }
    scanner.close();
}

From source file:Main.java

static Long toNumeric(String ip) {
    Scanner sc = new Scanner(ip).useDelimiter("\\.");
    Long l = (sc.nextLong() << 24) + (sc.nextLong() << 16) + (sc.nextLong() << 8) + (sc.nextLong());

    sc.close();/*from  www.j  av  a2 s.  c o  m*/
    return l;
}

From source file:org.eurekastreams.server.service.actions.strategies.activity.IterpolationListColliderTest.java

/**
 * Read an array of longs from a file.//from   w ww . j av a  2  s .  c  om
 * 
 * @param file
 *            the path to the file.
 * @param expectedSize
 *            the expected size of the list.
 * @return the array of longs.
 * @throws FileNotFoundException
 *             thrown if file can't be found.
 */
private static Long[] fileToList(final String file, final int expectedSize) throws FileNotFoundException {
    Scanner scanFile = new Scanner(new File(file));

    List<Long> list = new ArrayList<Long>();
    Scanner s = new Scanner(scanFile.nextLine());

    while (s.hasNextLong()) {
        list.add(s.nextLong());
    }

    Long[] arr = new Long[list.size()];

    list.toArray(arr);

    Assert.assertEquals(expectedSize, arr.length);

    return arr;
}

From source file:org.jdal.text.PeriodFormatter.java

/**
 * {@inheritDoc}//from   w  w  w .j ava  2 s  .  c  o m
 */
public Number parse(String text, Locale locale) throws ParseException {
    long value = 0;
    Scanner scanner = new Scanner(text);

    while (scanner.hasNext())
        value += parse(scanner.nextLong(), scanner.next("[dhms]"));

    scanner.close();

    return value;

}

From source file:flens.input.GraphiteInput.java

@Override
//metric_path value timestamp\n  
//http://graphite.wikidot.com/getting-your-data-into-graphite
public void readAndProcess(Pair<String, BufferedReader> inx) throws IOException {
    BufferedReader in = inx.getRight();
    String host = inx.getLeft();/*from w ww  .  j  a  v  a2s .  co  m*/
    String line = in.readLine();
    if (line == null)
        throw new IOException("connection lost");

    Scanner st = new Scanner(line);

    try {

        String metricName = st.next();
        String metric = st.next();
        long time = st.nextLong();

        Map<String, Object> tags = new HashMap<String, Object>();

        tags.put(Constants.METRIC, metricName);
        tags.put(Constants.VALUE, metric);

        Record r = Record.createWithTimeHostAndValues(time * 1000, host, tags);
        dispatch(r);
    } catch (NoSuchElementException e) {
        warn("line too short", line);
    }

}

From source file:com.amazonaws.mobileconnectors.pinpoint.analytics.Session.java

/**
 * Used by deserealizer//from w w w . j a  v a2s .c om
 *
 * @param sessionID
 * @param startTime
 * @param stopTime
 */
protected Session(final String sessionID, final String startTime, final String stopTime) {
    this.sessionIdTimeFormat = new SimpleDateFormat(
            SESSION_ID_DATE_FORMAT + SESSION_ID_DELIMITER + SESSION_ID_TIME_FORMAT, Locale.US);
    this.sessionIdTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    Scanner s = new Scanner(startTime);
    this.startTime = s.nextLong();
    s = new Scanner(stopTime);
    this.stopTime = s.nextLong();
    this.sessionID = sessionID;

    if (this.stopTime == Long.MIN_VALUE) {
        this.stopTime = null;
    }
}

From source file:org.romaframework.aspect.view.html.RequestParserImpl.java

private void bindValues(final Map<String, Map<String, Object>> reqParams) {
    final HtmlViewSession session = HtmlViewAspectHelper.getHtmlViewSession();
    for (final String groupName : reqParams.keySet()) {
        if (!(TransformerHelper.POJO_ACTION_PREFIX.equals(groupName)
                || TransformerHelper.POJO_EVENT_PREFIX.equals(groupName))) {
            Scanner s = new Scanner(groupName);
            if (s.hasNextLong()) {
                final Long fieldId = s.nextLong();
                final HtmlViewRenderable renderable = session.getRenderableById(fieldId);
                if (renderable != null) {
                    final HtmlViewBinder binder = renderable.getTransformer().getBinder(renderable);
                    if (binder instanceof ViewComponent) {
                        Roma.view().getScreen().setActiveArea(((ViewComponent) binder).getScreenArea());
                    }/*  www.  j  ava2s  .  c  o m*/
                    if (binder != null) {
                        // TODO handle BindingException
                        binder.bind(renderable, reqParams.get(groupName));
                    }
                }
            }
        }
    }
}

From source file:com.flexive.shared.value.FxSelectMany.java

/**
 * Evaluates the given string value to an object of type SelectMany.
 *
 * @param value comma seperated list of selected entries
 * @return the value interpreted as SelectMany
 *///w  w w  .j  a  va 2s  . c om
@Override
public SelectMany fromString(String value) {
    if (StringUtils.isEmpty(value))
        throw new FxInvalidParameterException("value", "ex.content.value.invalid.list").asRuntimeException();
    final List<FxSelectListItem> items = new ArrayList<FxSelectListItem>(10);
    final Scanner sc = new Scanner(value).useDelimiter(",");
    final FxEnvironment environment = CacheAdmin.getEnvironment();
    while (sc.hasNextLong()) {
        final long id = sc.nextLong();
        items.add(list != null ? list.getItem(id) : environment.getSelectListItem(id));
    }
    if (items.size() == 0)
        throw new FxInvalidParameterException("value", "ex.content.value.invalid.list").asRuntimeException();
    SelectMany sel = new SelectMany(items.get(0).getList());
    for (FxSelectListItem item : items)
        sel.selectItem(item);
    return sel;
}

From source file:org.apache.james.sieverepository.file.SieveFileRepository.java

@Override
public long getQuota() throws QuotaNotFoundException, StorageException {
    Long quota = null;//from   w  w w .  j a  va 2s .c om
    File file = getQuotaFile();
    if (file.exists()) {
        Scanner scanner = null;
        try {
            scanner = new Scanner(file, UTF_8);
            quota = scanner.nextLong();
        } catch (FileNotFoundException ex) {
            // no op
        } catch (NoSuchElementException ex) {
            // no op
        } finally {
            if (null != scanner) {
                scanner.close();
            }
        }
    }
    if (null == quota) {
        throw new QuotaNotFoundException("No default quota");
    }
    return quota;
}

From source file:org.apache.james.sieverepository.file.SieveFileRepository.java

@Override
public long getQuota(String user) throws QuotaNotFoundException, StorageException {
    Long quota = null;//from w w w  .  j a v a  2s  . c  om
    File file = getQuotaFile(user);
    if (file.exists()) {
        Scanner scanner = null;
        try {
            scanner = new Scanner(file, UTF_8);
            quota = scanner.nextLong();
        } catch (FileNotFoundException ex) {
            // no op
        } catch (NoSuchElementException ex) {
            // no op
        } finally {
            if (null != scanner) {
                scanner.close();
            }
        }
    }
    if (null == quota) {
        throw new QuotaNotFoundException("No quota for user: " + user);
    }
    return quota;
}