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:oracle.kv.hadoop.table.TableRecordReaderBase.java

private FieldRange createFieldRange(final Table table, final String rangeFieldProp) {
    FieldRange retRange = null;// w ww  .  j a  v  a  2s  .  c om

    if (rangeFieldProp == null) {
        return retRange;
    }

    final String missingLeftBraceStr = "invalid JSON format: system property does not begin "
            + "with left curly brace ['{']";
    final String missingRightBraceStr = "invalid JSON format: system property does not end "
            + "with right curly brace ['}']";
    if (!rangeFieldProp.startsWith("{")) {
        throw new IllegalArgumentException(missingLeftBraceStr);
    }
    if (!rangeFieldProp.endsWith("}")) {
        throw new IllegalArgumentException(missingRightBraceStr);
    }

    final String dq = "\"";
    final String colon = ":";
    final String missingNameBase = "missing required range field name ";

    /* Verify prop contains all required names in form, "requiredName": */
    for (String requiredName : requiredRangeNames) {
        final String missingName = missingNameBase + "[" + requiredName + "]";

        final int indxOf = rangeFieldProp.indexOf(dq + requiredName + dq + colon);

        if (indxOf < 0) {
            throw new IllegalArgumentException(missingName);
        }
    }

    /* Build FieldRange from system property inside curly braces. */
    String nameVal = null;
    String startVal = null;
    boolean startInclusive = true;
    String endVal = null;
    boolean endInclusive = true;
    FieldDef.Type fieldType = null;

    final String invalidComponentBase = "invalid JSON format: invalid \"name\":\"value\" pair "
            + "in system property ";

    /* Strip off the enclosing curly braces from system property. */
    final String prop = rangeFieldProp.substring(1, rangeFieldProp.length() - 1);

    final String[] propComponents = prop.split(",");
    for (String propComponent : propComponents) {

        final String invalidComponent = invalidComponentBase + "[" + propComponent + "]";

        /* Each component must be "name":"value" pair; otherwise errorr. */
        final String[] rangeComponents = propComponent.split(":");
        if (rangeComponents.length != 2) {
            throw new IllegalArgumentException(invalidComponent);
        }

        /*
         * Each name must be encapsulated by double quotes (verified above)
         * and each value of type STRING must be encapsulated by double
         * quotes. Scalar values are not encapsulated by double quotes.
         * Strip off double quotes before constructing the FieldRange.
         */
        final String name = rangeComponents[0].substring(1, rangeComponents[0].length() - 1);

        /* For values, handle both scalars and strings appropriately. */
        final String val = rangeComponents[1];
        if ("name".equals(name.toLowerCase())) {
            /* The name of the field over which to range is a STRING. */
            if (!(val.startsWith(dq) && val.endsWith(dq))) {
                throw new IllegalArgumentException(invalidComponent);
            }
            nameVal = val.substring(1, val.length() - 1);
            fieldType = table.getField(nameVal).getType();
        } else if ("start".equals(name.toLowerCase())) {
            /* Test for un-matched double quotes. */
            if (val.startsWith(dq) && !val.endsWith(dq)) {
                throw new IllegalArgumentException(invalidComponent);
            } else if (!val.startsWith(dq) && val.endsWith(dq)) {
                throw new IllegalArgumentException(invalidComponent);
            } else if (val.startsWith(dq) && val.endsWith(dq)) {
                startVal = val.substring(1, val.length() - 1); /* string */
            } else {
                startVal = val; /* scalar */
            }
        } else if ("startinclusive".equals(name.toLowerCase())) {
            startInclusive = Boolean.parseBoolean(val);
        } else if ("end".equals(name.toLowerCase())) {
            /* Test for un-matched double quotes. */
            if (val.startsWith(dq) && !val.endsWith(dq)) {
                throw new IllegalArgumentException(invalidComponent);
            } else if (!val.startsWith(dq) && val.endsWith(dq)) {
                throw new IllegalArgumentException(invalidComponent);
            } else if (val.startsWith(dq) && val.endsWith(dq)) {
                endVal = val.substring(1, val.length() - 1); /* string */
            } else {
                endVal = val; /* scalar */
            }
        } else if ("endinclusive".equals(name.toLowerCase())) {
            endInclusive = Boolean.parseBoolean(val);
        }
    }

    if (nameVal == null) {
        throw new IllegalArgumentException(invalidComponentBase);
    }
    if (startVal == null && fieldType == null) {
        throw new IllegalArgumentException(invalidComponentBase);
    }

    /* Verification complete. Construct the FieldRange return value. */

    retRange = table.createFieldRange(nameVal);

    if (FieldDef.Type.STRING.equals(fieldType)) {
        retRange.setStart(startVal, startInclusive);
        retRange.setEnd(endVal, endInclusive);
    } else {
        try {
            if (FieldDef.Type.INTEGER.equals(fieldType)) {
                retRange.setStart(Integer.parseInt(startVal), startInclusive);
                retRange.setEnd(Integer.parseInt(endVal), endInclusive);
            } else if (FieldDef.Type.LONG.equals(fieldType)) {
                retRange.setStart(Long.parseLong(startVal), startInclusive);
                retRange.setEnd(Long.parseLong(endVal), endInclusive);
            } else if (FieldDef.Type.FLOAT.equals(fieldType)) {
                retRange.setStart(Float.parseFloat(startVal), startInclusive);
                retRange.setEnd(Float.parseFloat(endVal), endInclusive);
            } else if (FieldDef.Type.DOUBLE.equals(fieldType)) {
                retRange.setStart(Double.parseDouble(startVal), startInclusive);
                retRange.setEnd(Double.parseDouble(endVal), endInclusive);
            } else {
                throw new IllegalArgumentException(invalidComponentBase);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(new NumberFormatException(invalidComponentBase));
        }
    }
    return retRange;
}

From source file:org.kalypso.wizard.KalypsoNAProjectWizard.java

public void mapRiver(final List sourceFeatureList, final HashMap mapping) {

    final Feature rootFeature = m_modelWS.getRootFeature();

    final Feature channelCollectionFE = (Feature) rootFeature
            .getProperty(NaModelConstants.CHANNEL_COLLECTION_MEMBER_PROP);
    final FeatureList channelList = (FeatureList) channelCollectionFE
            .getProperty(NaModelConstants.CHANNEL_MEMBER_PROP);
    final IRelationType targetRelation = channelList.getParentFeatureTypeProperty();

    // find column for id
    final String idColKey;
    if (mapping.containsKey("name")) //$NON-NLS-1$
    {//from   w ww . j a  va2  s.  co m
        idColKey = (String) mapping.get("name"); //$NON-NLS-1$ 
    } else
        idColKey = null;

    // StrangArt is defined in dummyFeatureType (member variable)
    final String typeKey = (String) mapping.get("StrangArt"); //$NON-NLS-1$
    // remove the channel type mapping (just needed once)
    mapping.remove(typeKey);

    for (int i = 0; i < sourceFeatureList.size(); i++) {
        final Feature sourceFeature = (Feature) sourceFeatureList.get(i);
        final Object o = sourceFeature.getProperty(typeKey);
        int channelType = 0;
        try {
            channelType = ((Integer) SpecialPropertyMapper.map(o.getClass(), Integer.class, o)).intValue();
        } catch (final Exception e) {
            e.printStackTrace();
            throw new NumberFormatException(Messages.get("KalypsoNAProjectWizard.ExceptionStrangArt")); //$NON-NLS-1$
        }

        Feature targetFeature = null;
        final String fid = getId(idColKey, sourceFeature, "S");
        switch (channelType) {
        case 0: {

            final IFeatureType vFT = getFeatureType("VirtualChannel"); //$NON-NLS-1$
            targetFeature = FeatureFactory.createFeature(channelCollectionFE, targetRelation, fid, vFT, true);
            break;
        }
        case 1: {

            final IFeatureType kmFT = getFeatureType("KMChannel"); //$NON-NLS-1$
            targetFeature = FeatureFactory.createFeature(channelCollectionFE, targetRelation, fid, kmFT, true);

            final IRelationType parameterMemberRT = (IRelationType) kmFT
                    .getProperty(NaModelConstants.KM_CHANNEL_PARAMETER_MEMBER);
            final List list = FeatureFactory.createFeatureList(targetFeature, parameterMemberRT);
            targetFeature.setProperty(parameterMemberRT, list);
            final int channelNo = Integer.parseInt(m_createPreferencePage.getKMChannelNo());
            for (int j = 0; j < channelNo; j++) {
                final IFeatureType kmParameterFT = parameterMemberRT.getTargetFeatureType();
                final Feature newFeature = m_modelWS.createFeature(targetFeature, targetRelation,
                        kmParameterFT);
                try {
                    m_modelWS.addFeatureAsComposition(targetFeature, parameterMemberRT, j, newFeature);
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }

            break;
        }
        case 2: {
            final IFeatureType storageFT = getFeatureType("StorageChannel"); //$NON-NLS-1$
            targetFeature = FeatureFactory.createFeature(channelCollectionFE, targetRelation, fid, storageFT,
                    true);
            break;
        }
        case 3: {
            throw new NotImplementedException(
                    Messages.get("KalypsoNAProjectWizard.ExceptionNotImplementedRHT")); //$NON-NLS-1$
        }
        default: {
            break;
        }
        }// switch
        final Iterator it = mapping.keySet().iterator();
        while (it.hasNext()) {
            final String targetkey = (String) it.next();
            final String sourcekey = (String) mapping.get(targetkey);
            if ("StrangArt".equals(targetkey))
                continue;
            if (!sourcekey.equalsIgnoreCase(NULL_KEY)) {
                final Object so = sourceFeature.getProperty(sourcekey);
                final IPropertyType pt = targetFeature.getFeatureType().getProperty(targetkey);
                if (so instanceof GM_MultiCurve) {
                    final GM_Curve[] curves = new GM_Curve[] { ((GM_MultiCurve) so).getCurveAt(0) };
                    targetFeature.setProperty(targetkey, curves[0]);
                }
                // if( so instanceof GMLMultiLineString )
                // targetFeature.setProperty( targetkey, so );
                else if (pt instanceof IValuePropertyType) {
                    final IValuePropertyType vpt = (IValuePropertyType) pt;
                    if (so.getClass().equals(vpt.getTypeHandler().getValueClass())) {
                        targetFeature.setProperty(targetkey, so);
                    } else {
                        try {
                            targetFeature.setProperty(targetkey, SpecialPropertyMapper.map(so.getClass(),
                                    vpt.getTypeHandler().getValueClass(), so));
                        } catch (final Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        channelList.add(targetFeature);

    } // for i

}

From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsReceivePaymentMainFragment.java

/**
 *  ?/*from w  w w. java  2  s. c om*/
 */
private boolean checkMoney(String money) {
    if (TextUtils.isEmpty(money)) {
        return false;
    }
    Double dMoney = 0.00;
    try {
        dMoney = Double.parseDouble(money);
    } catch (NumberFormatException e) {
        throw new NumberFormatException("??");
    }
    if (dMoney >= 0.01 && dMoney <= 5000.00) {
        mMoney = money;
        mDoubleMoney = dMoney;
        return true;
    }
    return false;
}

From source file:org.apache.hadoop.hive.druid.DruidStorageHandlerUtils.java

@Nullable
static Long getLongProperty(Table table, String propertyName) {
    String val = getTableProperty(table, propertyName);
    if (val == null) {
        return null;
    }//from w w w.  ja v  a2  s  . co m
    try {
        return Long.parseLong(val);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(String
                .format("Exception while parsing property[%s] with Value [%s] as Long", propertyName, val));
    }
}

From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsReceivePaymentMainFragment.java

/**
 *  /*from  w  w  w .j a va2 s. c  om*/
 */
private boolean checkFee(String fee) {
    Double dFee = 0.00;
    try {
        dFee = Double.parseDouble(fee);
    } catch (NumberFormatException e) {
        throw new NumberFormatException("?");
    }
    if (dFee > 0.00) {
        mFee = fee;
        return true;
    }
    return false;
}

From source file:edu.nyu.tandon.tool.BinnedRawHits.java

/**
 * Interpret the given command, changing the static variables.
 * See the help printing code for possible commands.
 *
 * @param line the command line.//from   w  ww.  ja  v a  2 s  .co m
 * @return false iff we should exit after this command.
 */
public boolean interpretCommand(final String line) {
    String[] part = line.substring(1).split("[ \t\n\r]+");

    final Command command;
    int i;

    if (part[0].length() == 0) {
        System.err.println("$                                                       prints this help.");
        System.err.println("$mode [time|short|long|snippet|trec <topicNo> <runTag>] chooses display mode.");
        System.err.println(
                "$limit <max>                                            output at most <max> results per query.");
        System.err.println(
                "$divert [<filename>]                                    diverts output to <filename> or to stdout.");
        System.err.println(
                "$weight {index:weight}                                  set index weights (unspecified weights are set to 1).");
        System.err.println("$mplex [<on>|<off>]                                     set/unset multiplex mode.");
        System.err.println(
                "$equalize <sample>                                      equalize scores using the given sample size.");
        System.err.println(
                "$score {<scorerClass>(<arg>,...)[:<weight>]}            order documents according to <scorerClass>.");
        System.err.println(
                "$expand {<expanderClass>(<arg>,...)}                    expand terms and prefixes according to <expanderClass>.");
        System.err.println("$quit                                                   quits.");
        return true;
    }

    try {
        command = Command.valueOf(part[0].toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("Invalid command \"" + part[0] + "\"; type $ for help.");
        return true;
    }

    switch (command) {
    case MODE:
        if (part.length >= 2) {
            try {
                final OutputType tempMode = OutputType.valueOf(part[1].toUpperCase());

                if (tempMode != OutputType.TREC && part.length > 2)
                    System.err.println("Extra arguments.");
                else if (tempMode == OutputType.TREC && part.length != 4)
                    System.err.println("Missing or extra arguments.");
                else {
                    displayMode = tempMode;
                    if (displayMode == OutputType.TREC) {
                        trecTopicNumber = Integer.parseInt(part[2]);
                        trecRunTag = part[3];
                    }
                }
            } catch (IllegalArgumentException e) {
                System.err.println("Unknown mode: " + part[1]);
            }
        } else
            System.err.println("Missing mode.");
        break;

    case LIMIT:
        int out = -1;
        if (part.length == 2) {
            try {
                out = Integer.parseInt(part[1]);
            } catch (NumberFormatException e) {
            }
            if (out >= 0)
                maxOutput = out;
        }
        if (out < 0)
            System.err.println("Missing or incorrect limit.");
        break;

    case SCORE:
        final Scorer[] scorer = new Scorer[part.length - 1];
        final double[] weight = new double[part.length - 1];
        for (i = 1; i < part.length; i++)
            try {
                weight[i - 1] = loadClassFromSpec(part[i], scorer, i - 1);
                if (weight[i - 1] < 0)
                    throw new IllegalArgumentException("Weights should be non-negative");
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        if (i == part.length)
            queryEngine.score(scorer, weight);
        break;

    case EXPAND:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else if (part.length == 1) {
            queryEngine.transformer(null);
        } else {
            QueryTransformer[] t = new QueryTransformer[1];
            try {
                loadClassFromSpec(part[1], t, 0);
                queryEngine.transformer(t[0]);
            } catch (Exception e) {
                System.err.print("Error while parsing specification: ");
                e.printStackTrace(System.err);
                break;
            }
        }
        break;

    case MPLEX:
        if (part.length != 2 || (part.length == 2 && !"on".equals(part[1]) && !"off".equals(part[1])))
            System.err.println("Wrong argument(s) to command");
        else {
            if (part.length > 1)
                queryEngine.multiplex = "on".equals(part[1]);
            System.err.println("Multiplex: " + part[1]);
        }
        break;

    case DIVERT:
        if (part.length > 2)
            System.err.println("Wrong argument(s) to command");
        else {
            if (outputDH != System.out)
                outputDH.close();
            outputPH.close();
            try {
                outputDH = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(
                                new FileOutputStream(part[1] + "-" + dhBatch++ + ".dh.txt")));
                outputPH = part.length == 1 ? System.out
                        : new PrintStream(new FastBufferedOutputStream(
                                new FileOutputStream(part[1] + "-" + phBatch++ + ".ph.txt")));
                outputName = part[1];
            } catch (FileNotFoundException e) {
                System.err.println("Cannot create file " + part[1]);
                outputDH = System.out;
                outputPH = System.out;
            }
        }
        break;

    case EQUALIZE:
        try {
            if (part.length != 2)
                throw new NumberFormatException("Illegal number of arguments");
            queryEngine.equalize(Integer.parseInt(part[1]));
            System.err.println("Equalization sample set to " + Integer.parseInt(part[1]));
        } catch (NumberFormatException e) {
            System.err.println(e.getMessage());
        }
        break;

    case QUIT:
        return false;
    }
    return true;
}

From source file:org.lwes.util.NumberCodec.java

/**
 * Decode a long out of a byte-array buffer. (convienience method)
 *
 * @param pBytes the byte array from which the encoded form should be read
 * @return long decoded from bytes/*  w  ww  . j  a  v  a 2s  .c  om*/
 */
public static long decodeLong(byte[] pBytes) throws NumberFormatException {
    if (pBytes == null) {
        throw new NumberFormatException("null byte array passed");
    }
    if (pBytes.length != NumberCodec.LONG_BYTES) {
        throw new NumberFormatException(
                "expecting byte array length of: " + NumberCodec.LONG_BYTES + " got: " + pBytes.length);
    }
    return NumberCodec.decodeLong(pBytes, 0, pBytes.length);
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * Code from Axis1 code base Note - We only follow the convention in the latest schema spec
 *
 * @param source/*w w w. j  a va2s.com*/
 * @return Returns Calendar.
 */
public static Calendar convertToDateTime(String source) {

    if ((source == null) || source.trim().equals("")) {
        return null;
    }
    source = source.trim();
    // the lexical representation of the date time as follows
    // '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
    Date date = null;
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.setLenient(false);

    if (source.startsWith("-")) {
        source = source.substring(1);
        calendar.set(Calendar.ERA, GregorianCalendar.BC);
    }

    int year = 0;
    int month = 0;
    int day = 0;
    int hour = 0;
    int minite = 0;
    int second = 0;
    long miliSecond = 0;
    int timeZoneOffSet = TimeZone.getDefault().getRawOffset();

    if ((source != null) && (source.length() >= 19)) {
        if ((source.charAt(4) != '-') || (source.charAt(7) != '-') || (source.charAt(10) != 'T')
                || (source.charAt(13) != ':') || (source.charAt(16) != ':')) {
            throw new RuntimeException("invalid date format (" + source + ") with out - s at correct place ");
        }
        year = Integer.parseInt(source.substring(0, 4));
        month = Integer.parseInt(source.substring(5, 7));
        day = Integer.parseInt(source.substring(8, 10));
        hour = Integer.parseInt(source.substring(11, 13));
        minite = Integer.parseInt(source.substring(14, 16));
        second = Integer.parseInt(source.substring(17, 19));

        int milliSecondPartLength = 0;

        if (source.length() > 19) {
            String rest = source.substring(19);
            if (rest.startsWith(".")) {
                // i.e this have the ('.'s+) part
                if (rest.endsWith("Z")) {
                    // this is in gmt time zone
                    timeZoneOffSet = 0;
                    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
                    miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("Z")));
                    milliSecondPartLength = rest.substring(1, rest.lastIndexOf("Z")).trim().length();
                } else if ((rest.lastIndexOf("+") > 0) || (rest.lastIndexOf("-") > 0)) {
                    // this is given in a general time zione
                    String timeOffSet = null;
                    if (rest.lastIndexOf("+") > 0) {
                        timeOffSet = rest.substring(rest.lastIndexOf("+") + 1);
                        miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("+")));
                        milliSecondPartLength = rest.substring(1, rest.lastIndexOf("+")).trim().length();
                        // we keep +1 or -1 to finally calculate the value
                        timeZoneOffSet = 1;

                    } else if (rest.lastIndexOf("-") > 0) {
                        timeOffSet = rest.substring(rest.lastIndexOf("-") + 1);
                        miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("-")));
                        milliSecondPartLength = rest.substring(1, rest.lastIndexOf("-")).trim().length();
                        // we keep +1 or -1 to finally calculate the value
                        timeZoneOffSet = -1;
                    }
                    if (timeOffSet.charAt(2) != ':') {
                        throw new RuntimeException(
                                "invalid time zone format (" + source + ") without : at correct place");
                    }
                    int hours = Integer.parseInt(timeOffSet.substring(0, 2));
                    int minits = Integer.parseInt(timeOffSet.substring(3, 5));
                    timeZoneOffSet = ((hours * 60) + minits) * 60000 * timeZoneOffSet;

                } else {
                    // i.e it does not have time zone
                    miliSecond = Integer.parseInt(rest.substring(1));
                    milliSecondPartLength = rest.substring(1).trim().length();
                }

            } else {
                if (rest.startsWith("Z")) {
                    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
                    // this is in gmt time zone
                    timeZoneOffSet = 0;
                } else if (rest.startsWith("+") || rest.startsWith("-")) {
                    // this is given in a general time zione
                    if (rest.charAt(3) != ':') {
                        throw new RuntimeException(
                                "invalid time zone format (" + source + ") without : at correct place");
                    }
                    int hours = Integer.parseInt(rest.substring(1, 3));
                    int minits = Integer.parseInt(rest.substring(4, 6));
                    timeZoneOffSet = ((hours * 60) + minits) * 60000;
                    if (rest.startsWith("-")) {
                        timeZoneOffSet = timeZoneOffSet * -1;
                    }
                } else {
                    throw new NumberFormatException("in valid time zone attribute");
                }
            }
        }
        calendar.set(Calendar.YEAR, year);
        // xml month is started from 1 and calendar month is started from 0
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minite);
        calendar.set(Calendar.SECOND, second);
        if (milliSecondPartLength != 3) {
            // milisecond part represenst the fraction of the second so we have to
            // find the fraction and multiply it by 1000. So if milisecond part
            // has three digits nothing required
            miliSecond = miliSecond * 1000;
            for (int i = 0; i < milliSecondPartLength; i++) {
                miliSecond = miliSecond / 10;
            }
        }
        calendar.set(Calendar.MILLISECOND, (int) miliSecond);
        calendar.set(Calendar.ZONE_OFFSET, timeZoneOffSet);
        // set the day light offset only if the time zone is present
        if (source.length() > 19) {
            calendar.set(Calendar.DST_OFFSET, 0);
        }

    } else {
        throw new NumberFormatException("date string can not be less than 19 characters");
    }

    return calendar;
}

From source file:org.lwes.util.NumberCodec.java

/**
 * Decode a int out of a byte-array buffer. (convienience method)
 *
 * @param pBytes the byte array from which the encoded form should be read
 * @return int decoded from bytes/*from   w ww  .j  a va2  s . co m*/
 */
public static int decodeInt(byte[] pBytes) throws NumberFormatException {
    if (pBytes == null) {
        throw new NumberFormatException("null byte array passed");
    }
    if (pBytes.length != NumberCodec.LONG_BYTES) {
        throw new NumberFormatException(
                "expecting byte array length of: " + NumberCodec.INT_BYTES + " got: " + pBytes.length);
    }
    return NumberCodec.decodeInt(pBytes, 0, pBytes.length);
}

From source file:com.netscape.cms.servlet.cert.DoRevoke.java

/**
 * This method parses a String serial number into BigInteger.
 *
 * @param serialNumber a String containing the un-normalized serial number
 * @return a BigInteger containing the serial number
 *//* www  .j a va 2 s .  c  o m*/
private BigInteger parseSerialNumber(String serialNumber) {

    if (StringUtils.isEmpty(serialNumber))
        return null;

    // Normalize the serialNumber
    serialNumber = serialNumber.trim();

    // find out if the value is hex or decimal

    //try decimal
    try {
        return new BigInteger(serialNumber, 10);
    } catch (NumberFormatException e) {
    }

    //try hex
    try {
        return new BigInteger(serialNumber, 16);
    } catch (NumberFormatException e) {
    }

    // give up if it isn't hex or dec
    throw new NumberFormatException("Invalid serial number: " + serialNumber);
}