Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:ispyb.client.common.shipping.UploadShipmentAction.java

/**
 * display/*ww w . ja v  a  2  s.c o  m*/
 * 
 * @param mapping
 * @param actForm
 * @param request
 * @param in_reponse
 * @return
 */
public ActionForward display(ActionMapping mapping, ActionForm actForm, HttpServletRequest request,
        HttpServletResponse in_reponse) {

    // Show BreadCrumbsForm if shipping selected
    try {
        String shippingId = request.getParameter(Constants.SHIPPING_ID);
        if (shippingId != null && !shippingId.equals("")) {
            Shipping3VO selectedShipping = DBTools.getSelectedShipping(Integer.decode(shippingId));
            BreadCrumbsForm.getIt(request).setSelectedShipping(selectedShipping);
        } else
            BreadCrumbsForm.getIt(request).setSelectedShipping(null);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Clean BreadCrumbsForm
    if (BreadCrumbsForm.getIt(request).getSelectedShipping() == null)
        BreadCrumbsForm.setIt(request, BreadCrumbsForm.getItClean(request));
    else
        BreadCrumbsForm.getIt(request).setSelectedDewar(null);

    // Retrieve Attributes
    UploadForm form = (UploadForm) actForm; // Parameters submited by form
    String selectedBeamlineName = form.getSelectedBeamline();

    // Populate Template
    String populatedTemplatePath = PopulateTemplate(request, false, false, false, null, null, false, 0, false,
            0);
    if (selectedBeamlineName != null) {
        String populatedTemplateAdvancedPath = PopulateTemplate(request, false, false, true,
                selectedBeamlineName, null, false, 0, false, 0);
    }
    form.setPopulatedTemplateURL(populatedTemplatePath);

    // Retrieve the list of beamlines for the current proposal having datamatrix codes scanned by SC
    try {
        // Get Proposal
        String proposalCode = (String) request.getSession().getAttribute(Constants.PROPOSAL_CODE);
        String proposalNumber = String.valueOf(request.getSession().getAttribute(Constants.PROPOSAL_NUMBER));
        Proposal3VO proposal = DBTools.getProposal(proposalCode, proposalNumber);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return mapping.findForward("uploadShipmentPage");
}

From source file:ws.argo.AsynchListener.AsynchListener.java

private ArrayList<ServiceInfoBean> parseProbeResponseXML(String xmlString) throws SAXException, IOException {
    ArrayList<ServiceInfoBean> serviceList = new ArrayList<ServiceInfoBean>();

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setCoalescing(true);/* w  w  w  .jav a 2 s . c  o  m*/
    DocumentBuilder builder = null;
    try {
        builder = builderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    InputStream is = IOUtils.toInputStream(xmlString);
    Document document = builder.parse(is);

    NodeList list = document.getElementsByTagName("service");

    for (int i = 0; i < list.getLength(); i++) {
        Element service = (Element) list.item(i);
        String contractID = null;
        String serviceID = null;

        contractID = service.getAttribute("contractID");
        serviceID = service.getAttribute("id");

        ServiceInfoBean config = new ServiceInfoBean(serviceID);

        config.serviceContractID = contractID;

        // Need some better error handling here.  The xml MUST have all config items in it 
        // or bad things happen.
        Node n;
        n = service.getElementsByTagName("ipAddress").item(0);
        config.ipAddress = ((Element) n).getTextContent();
        n = service.getElementsByTagName("port").item(0);
        config.port = ((Element) n).getTextContent();
        n = service.getElementsByTagName("url").item(0);
        config.url = ((Element) n).getTextContent();
        n = service.getElementsByTagName("data").item(0);
        config.data = ((Element) n).getTextContent();
        n = service.getElementsByTagName("description").item(0);
        config.description = ((Element) n).getTextContent();
        n = service.getElementsByTagName("contractDescription").item(0);
        config.contractDescription = ((Element) n).getTextContent();
        n = service.getElementsByTagName("serviceName").item(0);
        config.serviceName = ((Element) n).getTextContent();
        n = service.getElementsByTagName("consumability").item(0);
        config.consumability = ((Element) n).getTextContent();
        n = service.getElementsByTagName("ttl").item(0);
        config.ttl = Integer.decode(((Element) n).getTextContent());

        serviceList.add(config);

    }
    return serviceList;

}

From source file:org.sakaiproject.search.util.HTMLParser.java

public String next() {
    int tagend = clen - 1;
    int elend = -1;
    int tagstart = current + 1;
    boolean ignoreBefore = !(ignore > endstack);
    boolean ignoreAfter = ignoreBefore;

    for (int i = current; i < clen; i++) {
        if (elend == -1 && Character.isWhitespace(cbuf[i])) {
            elend = i;/*from  ww w .  j a  v a 2  s. c  o  m*/
        }
        if (cbuf[i] == '>') {
            tagend = i;
            if (elend == -1) {
                elend = tagend;
            }
            break;
        }
    }
    if (tagstart < clen) {
        if (cbuf[tagend - 1] == '/') {
        } else if (tagstart + 2 < clen && cbuf[tagstart] == '!' && cbuf[tagstart + 1] == '-'
                && cbuf[tagstart + 2] == '-') {
        } else if (cbuf[tagstart] == '/') {
            tagstart++;
            if (!notxml) {
                boolean match = true;
                if ((elend - tagstart) == (elementStack[endstack - 1] - elementStack[endstack - 2])) {
                    int j = elementStack[endstack - 2];
                    for (int i = 0; i < (elend - tagstart); i++) {
                        if (Character.toLowerCase(cbuf[tagstart + i]) != Character.toLowerCase(cbuf[j + i])) {
                            match = false;
                            break;
                        }
                    }
                }

                if (match) {
                    endstack -= 2;
                    ignoreAfter = !(ignore > endstack);
                } else {
                    notxml = true;
                }
            }
        } else {
            if (!notxml) {
                elementStack[endstack] = tagstart;
                elementStack[endstack + 1] = elend;
                endstack += 2;
                if (!ignoreAfter) {
                    for (int i = 0; i < IGNORE_TAGS.length; i++) {
                        if (IGNORE_TAGS[i].length == (elend - tagstart)) {
                            ignoreAfter = true;
                            for (int j = 0; j < IGNORE_TAGS[i].length; j++) {
                                if (IGNORE_TAGS[i][j] != Character.toLowerCase(cbuf[tagstart + j])) {
                                    ignoreAfter = false;
                                    break;
                                }
                            }
                            if (ignoreAfter) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    String t = "";
    if (notxml || !ignoreBefore) {
        if (true) {
            StringBuilder sb = new StringBuilder();

            for (int i = last; i < current; i++) {
                if (cbuf[i] == '&') {
                    if (cbuf[i + 1] == '#') {
                        for (int j = i; j < current; j++) {
                            if (cbuf[j] == ';') {
                                String entity = new String(cbuf, i + 2, j - (i + 2));
                                sb.append((char) Integer.decode(entity).intValue());
                                i = j;
                                break;
                            }
                        }
                    } else {
                        for (int j = i; j < current; j++) {
                            if (cbuf[j] == ';') {

                                String entity = new String(cbuf, i, j - i + 1);
                                String s = (String) entities.get(entity);
                                if (s == null) {
                                    s = entity;
                                } else if (s.length() > 0) {
                                    sb.append(s.charAt(0));
                                }
                                i = j;
                                break;
                            }
                        }
                    }
                } else {
                    sb.append(cbuf[i]);
                }
            }
            t = sb.toString();
        } else {
            t = new String(cbuf, last, current - last);
        }
    }
    last = tagend + 1;
    current = last;

    if (ignoreAfter) {
        if (!ignoreBefore) {
            ignore = endstack;
        }
    } else {
        ignore = endstack + 2;
    }
    return t;
}

From source file:it.geosolutions.opensdi.operations.NDVIStatisticsOperation.java

/**
 * Obtain file name for a NDVI for a String formatted as 'yyMmDecad'.<br />
 * For example, for the input String <code>13011</code> the result it's
 * <code>dv_20130101_20130110.tiff</code>
 * //  w w w.  j  a  v  a 2 s  .c  om
 * @param yearS
 * @param monthS
 * @param dekadS
 * @return NDVI file name for the parameters
 */
private String getNDVIFileName(String yearS, String monthS, String dekadS) {
    Integer year = Integer.decode(yearS);
    String mm = monthS.length() == 1 ? "0" + monthS : monthS;
    Integer month = Integer.decode(monthS);
    Dekad dekad = dekadS.equals("2") ? Dekad.SECOND : dekadS.equals("3") ? Dekad.THIRD : Dekad.FIRST;

    // First day: can be 01, 11 or 21
    String ddStart = DekadUtils.getFirstDay(year, month, dekad.ordinal()) + "";
    if (ddStart.length() == 1) {
        ddStart = "01";
    }
    // End day: can be: 10, 20 or the last day of the month
    Integer endDay = DekadUtils.getLastDay(year, month, dekad.ordinal());
    String ddEnd = endDay.toString();

    // Final name dv_20130101_20130110.tiff
    return NDVI_FILE_NAME_PREFIX + year + mm + ddStart + "_" + year + mm + ddEnd + NDVI_FILE_NAME_EXTENSION;
}

From source file:org.wonderbee.elasticsearch.hive.ElasticSearchHiveInputFormat.java

/**
 Starts an embedded elasticsearch client (ie. data = false)
 *///w ww  . j a  v a2  s  . c om
private void start_embedded_client() {
    if (this.hostPort != null) {
        LOG.info("Starting transport elasticsearch client ...");
        Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true).build();
        String[] split = this.hostPort.split(":");
        String host = split[0];
        int port = Integer.decode(split[1]);

        this.client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(host, port));
        LOG.info("Transport client started");
    } else {
        LOG.info("Starting embedded elasticsearch client ...");
        this.node = NodeBuilder.nodeBuilder().client(true).node();
        this.client = node.client();
        LOG.info("Embedded elasticsearch client started");
    }
}

From source file:com.wandisco.s3hdfs.rewrite.redirect.MetadataFileRedirect.java

/**
 * Sends a GET command to read a metadata file inside of HDFS.
 * It uses the URL from the modified URI to do so.
 * It will then consume the 307 response and read from the DataNode as well.
 *
 * @throws IOException/*w  w w . ja  v  a 2s  .c  o m*/
 */
public Properties sendHeadRead(String metadataPath, String nnHostAddress, String userName) throws IOException {
    // Set up HttpGet and get response
    String[] nnHost = nnHostAddress.split(":");
    GetMethod httpGet = (GetMethod) getHttpMethod(request.getScheme(), nnHost[0], Integer.decode(nnHost[1]),
            "OPEN", userName, ADD_WEBHDFS(metadataPath), GET);

    // Try up to 5 times to get the metadata
    httpClient.executeMethod(httpGet);
    LOG.info("1st response: " + httpGet.toString());
    System.out.println("1st response: " + httpGet.toString());

    for (int i = 0; i < 5 && httpGet.getStatusCode() == 403; i++) {
        httpGet.releaseConnection();
        httpClient.executeMethod(httpGet);
        LOG.info("Next response: " + httpGet.toString());
        System.out.println("Next response: " + httpGet.toString());
    }
    assert httpGet.getStatusCode() == 200;

    // Read metadata map
    InputStream is = httpGet.getResponseBodyAsStream();
    Properties metadata = new Properties();
    metadata.load(is);

    // Consume response remainder to re-allocate connection and return map
    httpGet.releaseConnection();
    return metadata;
}

From source file:orca.ip_assignment.OrcaNode.java

public boolean setPortsList(String list) {

    if ((list == null) || (list.trim().length() == 0))
        return true;

    String chkRegex = "(\\s*\\d+\\s*)(,(\\s*\\d+\\s*))*";

    if (list.matches(chkRegex)) {
        for (String port : list.split(",")) {
            int portI = Integer.decode(port.trim());
            if (portI > 65535)
                return false;
        }//w w  w  .  j  ava  2s. com
        openPorts = list;
        return true;
    }
    return false;
}

From source file:org.kchine.r.server.http.RHttpProxy.java

public static void logOffAndKill(String url, String sessionId) throws TunnelingException {
    if (System.getProperty("proxy_host") != null && !System.getProperty("proxy_host").equals("")) {
        mainHttpClient.getHostConfiguration().setProxy(System.getProperty("proxy_host"),
                Integer.decode(System.getProperty("proxy_port")));
    }/*from  ww w .ja v a2s.  c  o m*/
    GetMethod getLogOut = null;
    try {
        Object result = null;
        getLogOut = new GetMethod(url + "?method=logoff&kill=true");
        if (sessionId != null && !sessionId.equals("")) {
            getLogOut.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
            getLogOut.setRequestHeader("Cookie", "JSESSIONID=" + sessionId);
        }
        try {
            mainHttpClient.executeMethod(getLogOut);
            result = new ObjectInputStream(getLogOut.getResponseBodyAsStream()).readObject();
        } catch (ConnectException e) {
            throw new ConnectionFailedException();
        } catch (Exception e) {
            throw new TunnelingException("", e);
        }

        if (result != null && result instanceof TunnelingException) {
            throw (TunnelingException) result;
        }

    } finally {
        if (getLogOut != null) {
            getLogOut.releaseConnection();
        }
    }
}

From source file:net.sf.ehcache.config.BeanHandler.java

/**
 * Converts a string to an object of a particular class.
 *//*from   www . j a  v a  2s .c o m*/
private static Object convert(final Class toClass, final String value) throws Exception {
    if (value == null) {
        return null;
    }
    if (toClass.isInstance(value)) {
        return value;
    }
    if (toClass == Long.class || toClass == Long.TYPE) {
        return Long.decode(value);
    }
    if (toClass == Integer.class || toClass == Integer.TYPE) {
        return Integer.decode(value);
    }
    if (toClass == Boolean.class || toClass == Boolean.TYPE) {
        return Boolean.valueOf(value);
    }
    throw new Exception("Cannot convert attribute value to class " + toClass.getName());
}

From source file:net.frakbot.FWeather.util.LocationHelper.java

private long getMinUpdateInterval() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
    String valuePreference = sp.getString(Const.Preferences.SYNC_FREQUENCY, "300");
    int value = Integer.decode(valuePreference);
    if (value <= 0) {
        value = 300;//www .ja  v  a  2  s.c  o  m
        try {
            sp.edit().putString(Const.Preferences.SYNC_FREQUENCY, "300").commit();
        } catch (Exception ignored) {
        }
    }
    return value * 1000;
}