Example usage for java.lang NumberFormatException NumberFormatException

List of usage examples for java.lang NumberFormatException NumberFormatException

Introduction

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

Prototype

public NumberFormatException(String s) 

Source Link

Document

Constructs a NumberFormatException with the specified detail message.

Usage

From source file:sos.net.SOSFTPS.java

private void initProxy() {
    if (System.getProperty("proxyHost") != null && System.getProperty("proxyHost").length() > 0)
        this.setProxyHost(System.getProperty("proxyHost"));
    if (System.getProperty("proxyPort") != null && System.getProperty("proxyPort").length() > 0) {
        try {/*w w w.  j a  v  a 2  s .  c om*/
            this.setProxyPort(Integer.parseInt(System.getProperty("proxyPort")));
        } catch (Exception ex) {
            throw new NumberFormatException(
                    "Non-numeric value is set [proxyPort]: " + System.getProperty("proxyPort"));
        }
    }
    if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyHost").length() > 0)
        this.setProxyHost(System.getProperty("http.proxyHost"));
    if (System.getProperty("http.proxyPort") != null && System.getProperty("http.proxyPort").length() > 0) {
        try {
            this.setProxyPort(Integer.parseInt(System.getProperty("http.proxyPort")));
        } catch (Exception ex) {
            throw new NumberFormatException(
                    "Non-numeric value is set [http.proxyPort]: " + System.getProperty("http.proxyPort"));
        }
    }
}

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

/**
 * @since 3.0/*from w  w  w. j  a  va 2s  . co  m*/
 */
public static BigInteger bigIntegerDecode(final String nm) throws NumberFormatException {
    int radix = 10;
    int index = 0;
    boolean negative = false;
    BigInteger result;

    // Handle minus sign, if present
    if (nm.startsWith("-")) {
        negative = true;
        index++;
    }

    // Handle radix specifier, if present
    if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
        index += 2;
        radix = 16;
    } else if (nm.startsWith("#", index)) {
        index++;
        radix = 16;
    } else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
        index++;
        radix = 8;
    }

    if (nm.startsWith("-", index)) {
        throw new NumberFormatException("Negative sign in wrong position");
    }
    try {
        result = new BigInteger(nm.substring(index), radix);
        result = (negative) ? result.negate() : result;
    } catch (final NumberFormatException e) {
        // If number is Long.MIN_VALUE, we'll end up here. The next line
        // handles this case, and causes any genuine format error to be
        // rethrown.
        final String constant = (negative) ? "-" + nm.substring(index) : nm.substring(index);
        result = new BigInteger(constant, radix);
    }
    return result;
}

From source file:org.wso2.developerstudio.eclipse.gmf.esb.internal.persistence.AbstractEndpointTransformer.java

@SuppressWarnings("deprecation")
protected void createAdvanceOptions(EndpointFormPage endpointFormPage, AbstractEndpoint endpoint)
        throws NumberFormatException, JaxenException {

    EndpointDefinition synapseEPDef = new EndpointDefinition();
    EndpointCommons endpointCommons = endpointFormPage.getEndpointCommons();
    /**LEAVE_AS_IS,// w w  w  . ja va2  s. c  om
       SOAP_11,
       SOAP_12,
       POX,
       GET,
       REST,**/
    if (endpointFormPage.getEP_Format() != null) {
        if (endpointFormPage.getEP_Format().getSelectionIndex() == 1) {
            synapseEPDef.setFormat("soap11");
        } else if (endpointFormPage.getEP_Format().getSelectionIndex() == 2) {
            synapseEPDef.setFormat("soap12");
        } else if (endpointFormPage.getEP_Format().getSelectionIndex() == 3) {
            synapseEPDef.setFormat("pox");
        } else if (endpointFormPage.getEP_Format().getSelectionIndex() == 4) {
            synapseEPDef.setFormat("get");
        } else if (endpointFormPage.getEP_Format().getSelectionIndex() == 5) {
            synapseEPDef.setFormat("rest");
        } else {
            synapseEPDef.setFormat("LEAVE_AS_IS");
        }
    }

    if (endpointFormPage.getEP_Optimize() != null) {
        if (endpointFormPage.getEP_Optimize().getSelectionIndex() == 1) {
            synapseEPDef.setUseMTOM(true);
        } else if (endpointFormPage.getEP_Optimize().getSelectionIndex() == 2) {
            synapseEPDef.setUseSwa(true);
        }
    }

    if (endpointFormPage.getEndpointName() != null) {
        AspectConfiguration aspectConfiguration = new AspectConfiguration(
                endpointFormPage.getEndpointName().getText());
        synapseEPDef.configure(aspectConfiguration);
        if (endpointFormPage.getEndpointStatistics() != null) {
            if (endpointFormPage.getEndpointStatistics().getSelectionIndex() == 0) {
                aspectConfiguration.enableStatistics();
            } else {
                aspectConfiguration.disableStatistics();
            }
        }
    }

    if (endpointFormPage.getEndpointTrace() != null) {
        if (endpointFormPage.getEndpointTrace().getSelectionIndex() == 0) {
            synapseEPDef.getAspectConfiguration().enableTracing();
        } else {
            synapseEPDef.getAspectConfiguration().disableTracing();
        }
    }

    if (endpointCommons.getEndpointSuspendErrorCodes() != null) {
        String suspendErrorCodes = endpointCommons.getEndpointSuspendErrorCodes().getText();
        if (StringUtils.isNotEmpty(suspendErrorCodes)) {
            String[] suspendErrorCodesList = suspendErrorCodes.split("\\,");
            List<String> suspendCodes = Arrays.asList(suspendErrorCodesList);
            for (String code : suspendCodes) {
                try {
                    synapseEPDef.addSuspendErrorCode(Integer.parseInt(code));
                } catch (NumberFormatException ex) {
                    throw new NumberFormatException(
                            "Input for Suspend Error Codes is invalid,the value should be an interger");
                }
            }
        }
    }

    if (endpointCommons.getEndpointSuspendInitialDuration() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointSuspendInitialDuration().getText())) {
        try {
            synapseEPDef.setInitialSuspendDuration(
                    Long.parseLong(endpointCommons.getEndpointSuspendInitialDuration().getText().trim()));
        } catch (NumberFormatException ex) {
            throw new NumberFormatException(
                    "Input for Suspend Initial Duration is invalid,the value should be a long");
        }
    }

    if (endpointCommons.getEndpointSuspendMaxDuration() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointSuspendMaxDuration().getText())) {
        try {
            synapseEPDef.setSuspendMaximumDuration(
                    Long.parseLong(endpointCommons.getEndpointSuspendMaxDuration().getText().trim()));
        } catch (NumberFormatException ex) {
            throw new NumberFormatException(
                    "Input for Suspend Maximum Duration is invalid,the value should be a long");
        }

    }

    if (endpointCommons.getEndpointSuspendProgressFactor() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointSuspendProgressFactor().getText())) {
        try {
            synapseEPDef.setSuspendProgressionFactor(
                    Float.parseFloat((endpointCommons.getEndpointSuspendProgressFactor().getText().trim())));
        } catch (NumberFormatException ex) {
            throw new NumberFormatException(
                    "Input for Suspend Progression Factor is invalid,the value should be a float");
        }

    }

    if (endpointCommons.getEndpointRetryErrorCodes() != null) {
        String retryErrorCodes = endpointCommons.getEndpointRetryErrorCodes().getText();
        if (retryErrorCodes != null && !"".equals(retryErrorCodes) && !retryErrorCodes.isEmpty()) {
            String[] retryCodesList = retryErrorCodes.split("\\,");
            List<String> retryCodes = Arrays.asList(retryCodesList);
            for (String code : retryCodes) {
                try {
                    synapseEPDef.addTimeoutErrorCode(Integer.parseInt(code));
                } catch (NumberFormatException ex) {
                    throw new NumberFormatException(
                            "Input for Entry Error Codes is invalid,the value should be a float");
                }

            }
        }
    }

    if (endpointCommons.getEndpointRetryCount() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointRetryCount().getText())) {
        try {
            synapseEPDef.setRetriesOnTimeoutBeforeSuspend(
                    Integer.parseInt(endpointCommons.getEndpointRetryCount().getText().trim()));
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Input for Entry Count is invalid,the value should be a float");
        }
    }

    if (endpointCommons.getEndpointRetryDelay() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointRetryDelay().getText())) {
        try {
            synapseEPDef.setRetryDurationOnTimeout(
                    Integer.parseInt(endpointCommons.getEndpointRetryDelay().getText().trim()));
        } catch (NumberFormatException ex) {
            throw new NumberFormatException("Input for Entry Delay is invalid,the value should be a float");
        }
    }

    if (endpointCommons.getEndpointTimeoutAction() != null) {
        if (endpointCommons.getEndpointTimeoutAction().getSelectionIndex() != 0) {
            if (endpointCommons.getEndpointTimeoutAction().getSelectionIndex() == 1) {
                synapseEPDef.setTimeoutAction(101);
            } else {// endpointCommons.getEndpointTimeoutAction().getSelectionIndex()
                    // = 2
                synapseEPDef.setTimeoutAction(102);
            }
        } else {
            synapseEPDef.setTimeoutAction(100);
        }
    }

    if (endpointCommons.getEndpointTimeoutDuration() != null
            && StringUtils.isNotEmpty(endpointCommons.getEndpointTimeoutDuration().getText())) {
        try {
            String duration = endpointCommons.getEndpointTimeoutDuration().getText();
            Pattern pattern = Pattern.compile("\\{.*\\}");
            if (pattern.matcher(duration).matches()) {
                duration = duration.trim().substring(1, duration.length() - 1);
                SynapseXPath xpath = new SynapseXPath(duration);
                synapseEPDef.setDynamicTimeoutExpression(xpath);
            } else {
                long timeoutMilliSeconds = Long.parseLong(duration.trim());
                synapseEPDef.setTimeoutDuration(timeoutMilliSeconds);
            }
        } catch (NumberFormatException ex) {
            throw new NumberFormatException(
                    "Input for Timeout Duration is invalid,the value should be a number");
        } catch (JaxenException e) {
            throw e;
        }
    }

    if (endpointCommons.getEndpointAddressing() != null) {
        if (endpointCommons.getEndpointAddressing().getSelectionIndex() == 0) {
            synapseEPDef.setAddressingOn(true);
            synapseEPDef.setUseSeparateListener(
                    Boolean.valueOf(endpointCommons.getEndpointSeparateListner().getText().toString()));
            String version = endpointCommons.getEndpointVersion().getText();
            if (StringUtils.isNotEmpty(version)) {
                synapseEPDef.setAddressingVersion((version.equals("final")) ? "final" : "submission");
            }
        }
    }

    if (endpointCommons.getEndpointReliableMessaging() != null) {
        if (endpointCommons.getEndpointReliableMessaging().getSelectionIndex() == 0) {
            synapseEPDef.setReliableMessagingOn(true);
            String keyValue = endpointCommons.getEndpointReliableMessagingPolicyKey().getText();
            if (StringUtils.isNotEmpty(keyValue)) {
                synapseEPDef.setWsRMPolicyKey(keyValue);
            }
        }
    }

    if (endpointCommons.getEndpointSecurity() != null) {
        if (endpointCommons.getEndpointSecurity().getSelectionIndex() == 0) {
            synapseEPDef.setSecurityOn(true);

            if (StringUtils.isNotEmpty(endpointCommons.getEndpointWSPolicyKey().getText())) {
                String policyValue = endpointCommons.getEndpointWSPolicyKey().getText();
                synapseEPDef.setWsSecPolicyKey(policyValue);
            }

            if (StringUtils.isNotEmpty(endpointCommons.getEndpointSecurityInboundPolicyKey().getText())) {
                String inboundPolicyValue = endpointCommons.getEndpointSecurityInboundPolicyKey().getText();
                synapseEPDef.setInboundWsSecPolicyKey(inboundPolicyValue);
            }

            if (StringUtils.isNotEmpty(endpointCommons.getEndpointSecurityOutboundPolicyKey().getText())) {
                String outboundPolicyValue = endpointCommons.getEndpointSecurityOutboundPolicyKey().getText();
                synapseEPDef.setOutboundWsSecPolicyKey(outboundPolicyValue);
            }
        }
    }

    if (endpointFormPage.getEP_Description() != null) {
        if (StringUtils.isNotEmpty(endpointFormPage.getEP_Description().getText())) {
            endpoint.setDescription(endpointFormPage.getEP_Description().getText());
        }
    }
    endpoint.setDefinition(synapseEPDef);

}

From source file:org.rassee.omniture.pig.OmnitureDataLoader.java

@Override
public Tuple getNext() throws IOException {
    Tuple tuple;/* w ww  .ja va2 s  . c  o m*/
    Text value;
    Iterable<String> valueIterable;
    Iterator<String> valueIterator;
    int numberOfTabs;

    try {
        // Read the next key-value pair from the record reader.  If it's
        // finished, return null
        if (!reader.nextKeyValue())
            return null;

        value = reader.getCurrentValue();

        valueIterable = Splitter.on('\t').split(value.toString());
        numberOfTabs = Iterables.size(valueIterable);
        valueIterator = valueIterable.iterator();
    } catch (InterruptedException ie) {
        throw new IOException(ie);
    }

    // Create a new Tuple optimized for the number of fields that we know we'll need
    tuple = tupleFactory.newTuple(numberOfTabs + 1);

    if (numberOfTabs != fields.length) {
        LOGGER.error("skipping row - did not find expected tabs in row - expected {}, found {}", fields.length,
                numberOfTabs);
    } else {
        int fieldIndex = 0;
        while (valueIterator.hasNext()) {
            String val = valueIterator.next().trim();
            ResourceFieldSchema field = fields[fieldIndex];

            //field name starts with prop then
            //
            switch (field.getType()) {
            case DataType.INTEGER:
                if (StringUtils.isBlank(val)) {
                    tuple.set(fieldIndex, null);
                } else {
                    try {
                        tuple.set(fieldIndex, Integer.parseInt(val));
                    } catch (NumberFormatException nfe1) {
                        // Throw a more descriptive message
                        throw new NumberFormatException("Error while trying to parse " + val
                                + " into an Integer for field [fieldindex= " + fieldIndex + "] "
                                + field.getName() + "\n" + value.toString());
                    }
                }
                break;
            case DataType.DATETIME:
                if (StringUtils.isBlank(val)) {
                    tuple.set(fieldIndex, null);
                } else {
                    DATE_TIME_FORMATTER.parseDateTime(val);
                }
                break;
            case DataType.CHARARRAY:
                tuple.set(fieldIndex, val);
                break;
            case DataType.LONG:
                if (StringUtils.isBlank(val)) {
                    tuple.set(fieldIndex, null);
                } else {
                    try {
                        tuple.set(fieldIndex, Long.parseLong(val));
                    } catch (NumberFormatException nfe2) {
                        throw new NumberFormatException("Error while trying to parse " + val
                                + " into a Long for field " + field.getName() + "\n" + value.toString());
                    }
                }
                break;
            case DataType.BIGDECIMAL:
                if (StringUtils.isBlank(val)) {
                    tuple.set(fieldIndex, null);
                } else {
                    try {
                        tuple.set(fieldIndex, new BigDecimal(val));
                    } catch (NumberFormatException nfe2) {
                        throw new NumberFormatException("Error while trying to parse " + val
                                + " into a BigDecimal for field " + field.getName() + "\n" + value.toString());
                    }
                }
                break;
            case DataType.BAG:
                if ("event_list".equals(field.getName())) {
                    DataBag bag = bagFactory.newDefaultBag();
                    String[] events = val.split(",");

                    if (events == null) {
                        tuple.set(fieldIndex, null);
                    } else {
                        for (int j = 0; j < events.length; j++) {
                            Tuple t = tupleFactory.newTuple(1);
                            if (events[j] == "") {
                                t.set(0, null);
                            } else {
                                t.set(0, events[j]);
                            }
                            bag.add(t);
                        }
                        tuple.set(fieldIndex, bag);
                    }
                } else {
                    throw new IOException("Can not process bags for the field " + field.getName()
                            + ". Can only process for the event_list field.");
                }
                break;
            default:
                throw new IOException(
                        "Unexpected or unknown type in input schema (Omniture fields should be int, chararray or long): "
                                + field.getType());
            }

            fieldIndex++;
        }
    }

    return tuple;
}

From source file:org.nema.medical.mint.metadata.StudyIO.java

static public int hex2int(String hex) {
    if (hex.length() > 8)
        throw new NumberFormatException("max value is 32 bits (unsigned)");
    return (int) Long.parseLong(hex, 16);
}

From source file:org.jajuk.services.tags.JAudioTaggerTagImpl.java

@Override
public String getYear() throws Exception {
    String result = this.tag.getFirst(FieldKey.YEAR);
    if (StringUtils.isBlank(result)) {
        return "0";
    }/* w ww  .  j  a v  a  2 s . co m*/
    // The string contains at least a single character other than a digit, 
    // then try to parse the first four digits if any 
    if (PATTERN_NON_DIGIT.matcher(result).matches()) {
        Matcher matcher = PATTERN_FOUR_DIGITS.matcher(result);
        if (matcher.find()) {
            return matcher.group(1);
        } else {
            throw new NumberFormatException("Wrong year or date format");
        }
    } else {
        // Only digits
        return result;
    }
}

From source file:com.opengamma.web.json.FudgeMsgJSONReader.java

private int integerValue(final Object o) {
    if (o instanceof Number) {
        return ((Number) o).intValue();
    } else if (o instanceof String) {
        return Integer.parseInt((String) o);
    } else {//from w  ww  . java2  s.  c o  m
        throw new NumberFormatException(o + " is not a number");
    }
}

From source file:org.apache.spark.network.util.JavaUtils.java

/**
 * Convert a passed time string (e.g. 50s, 100ms, or 250us) to a time count in the given unit.
 * The unit is also considered the default if the given string does not specify a unit.
 *//*from   w  ww.ja v a  2  s  . co m*/
public static long timeStringAs(String str, TimeUnit unit) {
    String lower = str.toLowerCase().trim();

    try {
        Matcher m = Pattern.compile("(-?[0-9]+)([a-z]+)?").matcher(lower);
        if (!m.matches()) {
            throw new NumberFormatException("Failed to parse time string: " + str);
        }

        long val = Long.parseLong(m.group(1));
        String suffix = m.group(2);

        // Check for invalid suffixes
        if (suffix != null && !timeSuffixes.containsKey(suffix)) {
            throw new NumberFormatException("Invalid suffix: \"" + suffix + "\"");
        }

        // If suffix is valid use that, otherwise none was provided and use the default passed
        return unit.convert(val, suffix != null ? timeSuffixes.get(suffix) : unit);
    } catch (NumberFormatException e) {
        String timeError = "Time must be specified as seconds (s), "
                + "milliseconds (ms), microseconds (us), minutes (m or min), hour (h), or day (d). "
                + "E.g. 50s, 100ms, or 250us.";

        throw new NumberFormatException(timeError + "\n" + e.getMessage());
    }
}

From source file:com.edmunds.etm.runtime.api.ApplicationVersion.java

private static Integer getNextIntegerToken(StringTokenizer tok) {
    String s = tok.nextToken();/*ww  w .jav a2s  .  c o m*/
    if ((s.length() > 1) && s.startsWith("0")) {
        throw new NumberFormatException("Number part has a leading 0: '" + s + "'");
    }
    return Integer.valueOf(s);
}

From source file:com.cburch.draw.shapes.SvgReader.java

private static AbstractCanvasObject createPath(Element elt) {
    Matcher patt = PATH_REGEX.matcher(elt.getAttribute("d"));
    List<String> tokens = new ArrayList<String>();
    int type = -1; // -1 error, 0 start, 1 curve, 2 polyline
    while (patt.find()) {
        String token = patt.group();
        tokens.add(token);//from w  w w .  j  a  v  a2s  . c  om
        if (Character.isLetter(token.charAt(0))) {
            switch (token.charAt(0)) {
            case 'M':
                if (type == -1)
                    type = 0;
                else
                    type = -1;
                break;
            case 'Q':
            case 'q':
                if (type == 0)
                    type = 1;
                else
                    type = -1;
                break;
            /* not supported
            case 'L': case 'l':
            case 'H': case 'h':
            case 'V': case 'v':
               if (type == 0 || type == 2) type = 2;
               else type = -1;
               break;
            */
            default:
                type = -1;
            }
            if (type == -1) {
                throw new NumberFormatException("Unrecognized path command '" + token.charAt(0) + "'");
            }
        }
    }

    if (type == 1) {
        if (tokens.size() == 8 && tokens.get(0).equals("M") && tokens.get(3).toUpperCase().equals("Q")) {
            int x0 = Integer.parseInt(tokens.get(1));
            int y0 = Integer.parseInt(tokens.get(2));
            int x1 = Integer.parseInt(tokens.get(4));
            int y1 = Integer.parseInt(tokens.get(5));
            int x2 = Integer.parseInt(tokens.get(6));
            int y2 = Integer.parseInt(tokens.get(7));
            if (tokens.get(3).equals("q")) {
                x1 += x0;
                y1 += y0;
                x2 += x0;
                y2 += y0;
            }
            Location e0 = Location.create(x0, y0);
            Location e1 = Location.create(x2, y2);
            Location ct = Location.create(x1, y1);
            return new Curve(e0, e1, ct);
        } else {
            throw new NumberFormatException("Unexpected format for curve");
        }
    } else {
        throw new NumberFormatException("Unrecognized path");
    }
}