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:com.rapplogic.aru.core.SketchCore.java

/**
 * Parse an intel hex file into an array of bytes
 * /*  w  w w  .  ja v  a  2  s  . c o m*/
 * @param file
 * @return
 * @throws IOException
 */
public int[] parseIntelHex(String file) throws IOException {
    File hexFile = new File(file);

    int[] program = new int[MAX_PROGRAM_SIZE];

    // example:
    // length = 0x10
    // addr = 0000
    // type = 00
    //:100000000C94C7010C94EF010C94EF010C94EF01D8
    //:061860000994F894FFCF8B
    //:00000001FF

    List<String> hex = Files.readLines(hexFile, Charset.forName("UTF-8"));

    int lineCount = 0;
    int position = 0;

    for (String line : hex) {

        String dataLine = line.split(":")[1];

        //System.out.println("line: " + ++lineCount + ": " + line);

        int checksum = 0;

        if (line.length() > 10) {
            int length = Integer.decode("0x" + dataLine.substring(0, 2));
            int address = Integer.decode("0x" + dataLine.substring(2, 6));
            int type = Integer.decode("0x" + dataLine.substring(6, 8));

            checksum += length + address + type;

            //System.out.println("Length is " + length + ", address is " + Integer.toHexString(address) + ", type is " + Integer.toHexString(type));

            // Ignore all record types except 00, which is a data record. 
            // Look out for 02 records which set the high order byte of the address space
            if (type == 0) {
                // Normal data record
            } else if (type == 4 && length == 2 && address == 0 && line.length() > 12) {
                // Address > 16bit not supported by Arduino so not important
                throw new RuntimeException("Record type 4 is not implemented");
            } else {
                //System.out.println("Skipped: " + line);
                continue;
            }

            // verify the addr matches our current array position
            if (position > 0 && position != address) {
                throw new RuntimeException("Expected address of " + position + " but was " + address);
            }

            // address will always be last position or we'd have gaps in the array
            position = address;

            {
                int i = 8;
                // data starts at 8 (4th byte) to end minus checksum
                for (; i < 8 + (length * 2); i += 2) {
                    int b = Integer.decode("0x" + dataLine.substring(i, i + 2));
                    checksum += b;
                    // what we're doing here is simply parsing the data portion of each line and adding to the array

                    if (position >= MAX_PROGRAM_SIZE) {
                        throw new RuntimeException(
                                "Program is too large for Arduino. Max size is " + MAX_PROGRAM_SIZE);
                    }

                    program[position] = b;
                    position++;
                }

                //System.out.println("Program data: " + toHex(program, position - length, length));

                // we should be at the checksum position
                if (i != dataLine.length() - 2) {
                    throw new RuntimeException("Line length does not match expected length " + length);
                }

                // checksum
                int expectedChecksum = Integer.decode("0x" + line.substring(line.length() - 2, line.length()));
                //System.out.println("Expected checksum is " + line.substring(line.length() - 2, line.length()));

                //checksum+= expectedChecksum;
                // TODO somethings not right
                checksum = 0xff - checksum & 0xff;

                //System.out.println("Checksum is " + Integer.toHexString(checksum & 0xff));
            }
        }
    }

    int[] resize = new int[position];
    System.arraycopy(program, 0, resize, 0, position);

    return resize;
}

From source file:org.jbpm.formModeler.core.processing.formProcessing.Functions.java

public Map getValidDays(String value) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.DAY_OF_MONTH, 1);

    if (value == null || value.equals("") || value.startsWith("/")) {
        gc.set(GregorianCalendar.MONTH, 0);
    } else if (value.endsWith("/")) {
        int month = Integer.decode(value.substring(0, value.indexOf("/"))).intValue();
        gc.set(GregorianCalendar.MONTH, month);
    } else {/*w  w w.j a va2  s.com*/
        SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
        try {
            gc.setTime(sdf.parse(value));
            gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) + 1);
        } catch (Exception e) {
            log.warn("Error parsing date " + value + " : ", e);
        }
    }

    Map days = new TreeMap();

    int month = gc.get(GregorianCalendar.MONTH);
    while (gc.get(GregorianCalendar.MONTH) == month) {
        int intValue = gc.get(GregorianCalendar.DAY_OF_MONTH);
        String key = java.lang.String.valueOf(intValue);
        if (key.length() == 1)
            key = "0" + key;
        days.put(key, key);
        gc.set(GregorianCalendar.DAY_OF_MONTH, intValue + 1);
    }

    return days;
}

From source file:net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter.java

@Override
public String format(String text) {
    String result = Objects.requireNonNull(text);

    if (result.isEmpty()) {
        return result;
    }//from  www.  j  a  v a  2  s  .  co  m

    StringBuilder sb = new StringBuilder();
    // Deal with the form <sup>k</sup>and <sub>k</sub>
    result = result.replaceAll("<[ ]?sup>([^<]+)</sup>", "\\\\textsuperscript\\{$1\\}");
    result = result.replaceAll("<[ ]?sub>([^<]+)</sub>", "\\\\textsubscript\\{$1\\}");

    // TODO: maybe rewrite this based on regular expressions instead
    // Note that (at least) the IEEE Xplore fetcher must be fixed as it relies on the current way to
    // remove tags for its image alt-tag to equation converter
    for (int i = 0; i < result.length(); i++) {

        int c = result.charAt(i);

        if (c == '<') {
            i = readTag(result, i);
        } else {
            sb.append((char) c);
        }

    }
    result = sb.toString();

    // Handle text based HTML entities
    Set<String> patterns = HTMLUnicodeConversionMaps.HTML_LATEX_CONVERSION_MAP.keySet();
    for (String pattern : patterns) {
        result = result.replace(pattern, HTMLUnicodeConversionMaps.HTML_LATEX_CONVERSION_MAP.get(pattern));
    }

    // Handle numerical HTML entities
    Matcher m = ESCAPED_PATTERN.matcher(result);
    while (m.find()) {
        int num = Integer.decode(m.group(1).replace("x", "#") + m.group(3));
        if (HTMLUnicodeConversionMaps.NUMERICAL_LATEX_CONVERSION_MAP.containsKey(num)) {
            result = result.replace("&#" + m.group(1) + m.group(2) + m.group(3) + ";",
                    HTMLUnicodeConversionMaps.NUMERICAL_LATEX_CONVERSION_MAP.get(num));
        }
    }

    // Combining accents
    m = ESCAPED_PATTERN2.matcher(result);
    while (m.find()) {
        int num = Integer.decode(m.group(2).replace("x", "#") + m.group(4));
        if (HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.containsKey(num)) {
            if ("i".equals(m.group(1))) {
                result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";",
                        "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{\\i}}");
            } else if ("j".equals(m.group(1))) {
                result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";",
                        "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{\\j}}");
            } else {
                result = result.replace(m.group(1) + "&#" + m.group(2) + m.group(3) + m.group(4) + ";",
                        "{\\" + HTMLUnicodeConversionMaps.ESCAPED_ACCENTS.get(num) + "{" + m.group(1) + "}}");
            }
        }
    }

    // Find non-converted numerical characters
    m = ESCAPED_PATTERN3.matcher(result);
    while (m.find()) {
        int num = Integer.decode(m.group(1).replace("x", "#") + m.group(3));
        LOGGER.warn("HTML escaped char not converted: " + m.group(1) + m.group(2) + m.group(3) + " = "
                + Integer.toString(num));
    }

    // Remove $$ in case of two adjacent conversions
    result = result.replace("$$", "");

    // Find non-covered special characters with alphabetic codes
    m = ESCAPED_PATTERN4.matcher(result);
    while (m.find()) {
        LOGGER.warn("HTML escaped char not converted: " + m.group(1));
    }

    return result.trim();
}

From source file:stroom.streamstore.server.fs.FileSystemUtil.java

public static String decodeFileName(String fileName) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < fileName.length(); i++) {
        char c = fileName.charAt(i);
        if (c == '#') {
            c = (char) Integer.decode("0x" + fileName.substring(i + 1, i + 4)).intValue();
            builder.append(c);/*from  w  ww  .j ava2  s .  co m*/
            i = i + 3;
        } else {
            builder.append(c);
        }
    }
    return builder.toString();
}

From source file:net.bither.bitherj.utils.TransactionsUtil.java

public static List<In> getInSignatureFromBither(String str) {
    List<In> result = new ArrayList<In>();
    if (str.length() > 0) {
        String[] txs = str.split(";");
        for (String tx : txs) {
            String[] ins = tx.split(":");
            byte[] txHash = Utils.reverseBytes(Base64.decode(ins[0], Base64.URL_SAFE));
            for (int i = 1; i < ins.length; i++) {
                String[] array = ins[i].split(",");
                int inSn = Integer.decode(array[0]);
                byte[] inSignature = Base64.decode(array[1], Base64.URL_SAFE);
                In in = new In();
                in.setTxHash(txHash);// ww  w. ja v a 2  s .co  m
                in.setInSn(inSn);
                in.setInSignature(inSignature);
                result.add(in);
            }
        }
    }
    return result;
}

From source file:org.apache.sling.cassandra.resource.provider.security.AccessControlUtil.java

private int getPrivilegeFromACE(String ace) {
    return Integer.decode(ace.split(":")[1].trim());
}

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

public static String logOn(String url, String sessionId, String login, String pwd,
        HashMap<String, Object> options) throws TunnelingException {
    if (System.getProperty("proxy_host") != null && !System.getProperty("proxy_host").equals("")) {
        System.out.println(//  w  ww.j  ava  2 s .c o  m
                ">>Using Proxy :" + System.getProperty("proxy_host") + ":" + System.getProperty("proxy_port"));
        mainHttpClient.getHostConfiguration().setProxy(System.getProperty("proxy_host"),
                Integer.decode(System.getProperty("proxy_port")));
    }
    GetMethod pingServer = null;
    try {
        Object result = null;
        try {
            pingServer = new GetMethod(url + "?method=ping");

            mainHttpClient.executeMethod(pingServer);
            result = new ObjectInputStream(pingServer.getResponseBodyAsStream()).readObject();
            if (!result.equals("pong"))
                throw new ConnectionFailedException();

            System.out.println("Ping succeeded");
        } catch (Exception e) {
            e.printStackTrace();
            throw new ConnectionFailedException();
        }
    } finally {
        if (pingServer != null) {
            pingServer.releaseConnection();
        }
    }

    GetMethod getSession = null;
    try {
        Object result = null;
        try {
            getSession = new GetMethod(url + "?method=logon&login=" + PoolUtils.objectToHex(login) + "&pwd="
                    + PoolUtils.objectToHex(pwd) + "&options=" + PoolUtils.objectToHex(options));

            getSession.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
            if (sessionId != null && !sessionId.equals("")) {
                getSession.setRequestHeader("Cookie", "JSESSIONID=" + sessionId);
            } else {
                getSession.setRequestHeader("Cookie", "JSESSIONID=" + "");
            }
            mainHttpClient.executeMethod(getSession);
            result = new ObjectInputStream(getSession.getResponseBodyAsStream()).readObject();
        } catch (ConnectException e) {
            e.printStackTrace();
            throw new ConnectionFailedException();
        } catch (Exception e) {
            e.printStackTrace();
            throw new TunnelingException("Client Side", e);
        }

        if (result != null && result instanceof TunnelingException) {
            throw (TunnelingException) result;
        }
        return (String) result;
    } finally {
        if (getSession != null) {
            getSession.releaseConnection();
        }
    }
}

From source file:org.ossie.properties.AnyUtils.java

/**
 * Attempts to convert the string value to the appropriate Java type.
 * /*from   ww  w .  ja  va2 s .  c  o m*/
 * @param stringValue the string form of the value
 * @param type the string form of the TypeCode
 * @return A Java object of theString corresponding to the typecode
 */
public static Object convertString(final String stringValue, final String type) {
    if (stringValue == null) {
        return null;
    }
    if (type.equals("string")) {
        return stringValue;
    } else if (type.equals("wstring")) {
        return stringValue;
    } else if (type.equals("boolean")) {
        if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) {
            return Boolean.parseBoolean(stringValue);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid boolean value");
    } else if (type.equals("char")) {
        if (stringValue.length() == 1) {
            return stringValue.charAt(0);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid char value");
    } else if (type.equals("wchar")) {
        return stringValue.charAt(0);
    } else if (type.equals("double")) {
        return Double.parseDouble(stringValue);
    } else if (type.equals("float")) {
        return Float.parseFloat(stringValue);
    } else if (type.equals("short")) {
        return Short.decode(stringValue);
    } else if (type.equals("long")) {
        return Integer.decode(stringValue);
    } else if (type.equals("longlong")) {
        return Long.decode(stringValue);
    } else if (type.equals("ulong")) {
        final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L;
        final Long retVal = Long.decode(stringValue);
        if (retVal < 0 || retVal > MAX_UINT) {
            throw new IllegalArgumentException(
                    "ulong value must be greater than '0' and less than " + MAX_UINT);
        }
        return retVal;
    } else if (type.equals("ushort")) {
        final int MAX_USHORT = 2 * Short.MAX_VALUE + 1;
        final Integer retVal = Integer.decode(stringValue);
        if (retVal < 0 || retVal > MAX_USHORT) {
            throw new IllegalArgumentException(
                    "ushort value must be greater than '0' and less than " + MAX_USHORT);
        }
        return retVal;
    } else if (type.equals("ulonglong")) {
        final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2))
                .add(BigInteger.ONE);
        final BigInteger retVal = bigIntegerDecode(stringValue);
        if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) {
            throw new IllegalArgumentException(
                    "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString());
        }
        return retVal;
    } else if (type.equals("objref")) {
        List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:");
        for (String prefix : objrefPrefix) {
            if (stringValue.startsWith(prefix)) {
                return stringValue;
            }
        }
        throw new IllegalArgumentException(stringValue + " is not a valid objref value");
    } else if (type.equals("octet")) {
        final short MIN_OCTET = 0;
        final short MAX_OCTET = 0xFF;
        short val = Short.valueOf(stringValue);
        if (val <= MAX_OCTET && val >= MIN_OCTET) {
            return Short.valueOf(val).byteValue();
        }
        throw new IllegalArgumentException(stringValue + " is not a valid octet value");
    } else {
        throw new IllegalArgumentException("Unknown CORBA Type: " + type);
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            legend, true, false);/*from   w w  w  .  j  av  a  2 s .com*/

    /*Font font = new Font("Tahoma", Font.BOLD, titleDimension);
    TextTitle title = new TextTitle(name, font);
    chart.setTitle(title);*/

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    Color colorSubInvisibleTitle = Color.decode("#FFFFFF");
    StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle);
    TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle);
    chart.addSubtitle(subsubTitle);

    chart.setBackgroundPaint(color);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    //plot.setForegroundAlpha(0.50f);
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //define colors
    int seriesN = dataset.getSeriesCount();
    if (colorMap != null) {
        boolean isSerieSel = true;
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            String tmpName = serieName.replaceAll(" ", "");
            tmpName = tmpName.replace('.', ' ').trim();
            if (serie_selected != null && serie_selected.size() > 0) {
                String serieSel = serie_selected.get(tmpName).toString();
                isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES")
                        || serieSel.equalsIgnoreCase("1")) ? true : false;
                serieName = tmpName;
            }

            if (color != null && isSerieSel) {
                Color color = (Color) colorMap.get(serieName);
                renderer.setSeriesPaint(i, color);
            } else {
                Color color = new Color(Integer.decode(defaultColor).intValue());
                renderer.setSeriesPaint(i, color);
            }
        }
    }

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setAutoRange(true);
    domainAxis.setRange(yMin, yMax);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());

    //rangeAxis.setAutoRange(true);
    rangeAxis.setRange(xMin, xMax);

    TickUnits units = null;
    if (decimalXValues == false)
        units = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        units = (TickUnits) NumberAxis.createStandardTickUnits();
    rangeAxis.setStandardTickUnits(units);

    TickUnits domainUnits = null;
    if (decimalYValues == false)
        domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        domainUnits = (TickUnits) NumberAxis.createStandardTickUnits();
    domainAxis.setStandardTickUnits(domainUnits);

    rangeAxis.setLowerMargin(1.0);
    rangeAxis.setUpperMargin(1.0);

    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());

    domainAxis.setLowerMargin(1.0);
    domainAxis.setUpperMargin(1.0);
    //DecimalFormat format=(new DecimalFormat("0"));
    //rangeAxis.setNumberFormatOverride(format);

    if (legend == true)
        drawLegend(chart);

    return chart;
}

From source file:com.symbian.driver.core.controller.PCVisitor.java

/**
 * Constructor for HostVisitor.//from  w ww .j av  a 2 s.  com
 * 
 * Creates the stack of UID's.
 */
public PCVisitor() {
    // Prepare a UID set to be used when creating sis files.
    String lUidFirstLiteral = null;
    String lUidLastLiteral = null;
    TDConfig CONFIG = TDConfig.getInstance();
    try {
        lUidFirstLiteral = CONFIG.getPreference(TDConfig.UIDFIRST);
        lUidLastLiteral = CONFIG.getPreference(TDConfig.UIDLAST);
    } catch (ParseException lParseException) {
        LOGGER.log(Level.WARNING, "Could not get the preference for the first and last UID.", lParseException);
    }

    int lUidFirstInt = 0x10210D02;
    int lUidLastInt = 0x10210D32;

    try {
        if (lUidFirstLiteral != null && !lUidFirstLiteral.equalsIgnoreCase("0")
                && !lUidFirstLiteral.equalsIgnoreCase("")) {
            lUidFirstInt = Integer.decode(lUidFirstLiteral).intValue();
        }
        if (lUidLastLiteral != null && !lUidLastLiteral.equalsIgnoreCase("0")
                && !lUidLastLiteral.equalsIgnoreCase("")) {
            lUidLastInt = Integer.decode(lUidLastLiteral).intValue();
        }
    } catch (NumberFormatException lNumberFormatException) {
        LOGGER.log(Level.WARNING, "Please specifiy correct UID number ranges.", lNumberFormatException);
    }

    // Configures the UID set
    if (UID_LIST.size() == 0) {
        for (int lUidIndex = lUidFirstInt; lUidIndex <= lUidLastInt; lUidIndex++) {
            UID_LIST.add("0x" + Integer.toHexString(lUidIndex));
        }

        if (UID_LIST.size() != 49) {
            LOGGER.log(Level.SEVERE, "Could not intilaise UID stack, stack is of size: " + UID_LIST.size());
        }
    }
}