Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java

private int parseStatusLine(PushbackInputStream in, StringBuffer line) throws IOException, HttpException {
    readLine(in, line, false);//from  ww w  . j  a va2 s .  c o m

    int codeStart = line.indexOf(" ");
    int codeEnd = line.indexOf(" ", codeStart + 1);

    // handle lines with no plaintext result code, ie:
    // "HTTP/1.1 200" vs "HTTP/1.1 200 OK"
    if (codeEnd == -1)
        codeEnd = line.length();

    int code;
    try {
        code = Integer.parseInt(line.substring(codeStart + 1, codeEnd));
    } catch (NumberFormatException e) {
        throw new HttpException("bad status line '" + line + "': " + e.getMessage(), e);
    }

    return code;
}

From source file:com.alvermont.terraj.planet.ui.PlanetCLI.java

private AllPlanetParameters processOptions(String[] args) {
    AllPlanetParameters params = new AllPlanetParameters();

    final LongOpt[] options = getOptionArray();
    final String shortOpts = getShortOptions(options);
    final Getopt g = new Getopt("planetgen", args, shortOpts, options, true);

    int c;//from   w w w  .  j av  a  2s  .  c  om

    while (params != null && (c = g.getopt()) != -1) {
        final String arg = g.getOptarg();

        try {
            switch ((char) c) {
            case 's':

                final double seed = Double.parseDouble(arg);
                params.getPlanetParameters().setSeed(seed);

                break;

            case 'w':

                final int width = Integer.parseInt(arg);
                params.getProjectionParameters().setWidth(width);

                break;

            case 'h':

                final int height = Integer.parseInt(arg);
                params.getProjectionParameters().setHeight(height);

                break;

            case 'o':
                params.getProjectionParameters().setOutputFile(arg);

                break;

            case 'm':

                final double mag = Double.parseDouble(arg);
                params.getProjectionParameters().setScale(mag);

                break;

            case 'l':

                final double lon = Double.parseDouble(arg);
                params.getProjectionParameters().setLon(lon);

                break;

            case 'L':

                final double lat = Double.parseDouble(arg);
                params.getProjectionParameters().setLat(lat);

                break;

            case 'g':

                final double vgrid = Double.parseDouble(arg);
                params.getProjectionParameters().setVgrid(vgrid);

                break;

            case 'G':

                final double hgrid = Double.parseDouble(arg);
                params.getProjectionParameters().setHgrid(hgrid);

                break;

            case 'i':

                final double initAlt = Double.parseDouble(arg);
                params.getPlanetParameters().setInitialAltitude(initAlt);

                break;

            case 'c':
                params.getProjectionParameters().setLatic(true);

                break;

            case 'C':

                final int light = params.getProjectionParameters().getLighterColours();
                params.getProjectionParameters().setLighterColours(light + 1);

                break;

            case 'N':
                System.err.println("The N option is not currently supported");
                params = null;

                break;

            case 'a':
                params.getProjectionParameters().setAltColors(true);

                break;

            case 'M':
                params.getProjectionParameters().setColourFile(arg);

                break;

            case '?':
                params = null;

                break;

            case 'O':
                params.getProjectionParameters().setOutline(true);

                break;

            case 'E':
                params.getProjectionParameters().setEdges(true);

                break;

            case 'B':
                params.getProjectionParameters().setDoShade(true);

                break;

            case 'A':

                final double angle = Double.parseDouble(arg);
                params.getProjectionParameters().setShadeAngle(angle);

                break;

            case 'b':
                params.getProjectionParameters().setReverseBackground(true);

                break;

            case 'V':

                final double dd1 = Double.parseDouble(arg);
                params.getPlanetParameters().setDistanceWeight(dd1);

                break;

            case 'v':

                final double dd2 = Double.parseDouble(arg);
                params.getPlanetParameters().setAltitudeDifferenceWeight(dd2);

                break;

            case 'p':
                params.getProjectionParameters().setProjectionName(arg);

                break;

            default:
                System.err.println("Unexpected option encountered: " + (char) c);
                params = null;

                break;
            }
        } catch (NumberFormatException ex) {
            System.err.println("Expecting a numeric option: " + ex.getMessage());

            params = null;
        }

        System.out.println("arg= " + (char) c + " val= " + arg);
    }

    return params;
}

From source file:fr.ens.biologie.genomique.eoulsan.actions.ExecJarHadoopAction.java

@Override
public void action(final List<String> arguments) {

    final Options options = makeOptions();
    final CommandLineParser parser = new GnuParser();

    String jobDescription = null;
    String jobEnvironment = null;
    long millisSinceEpoch = System.currentTimeMillis();

    int argsOptions = 0;

    try {// w  ww  .  ja v a  2 s .  c om

        // parse the command line arguments
        final CommandLine line = parser.parse(options, arguments.toArray(new String[arguments.size()]), true);

        // Help option
        if (line.hasOption("help")) {
            help(options);
        }

        if (line.hasOption("d")) {

            jobDescription = line.getOptionValue("d");
            argsOptions += 2;
        }

        if (line.hasOption("e")) {

            jobEnvironment = line.getOptionValue("e");
            argsOptions += 2;
        }

        if (line.hasOption("p")) {

            try {
                millisSinceEpoch = Long.parseLong(line.getOptionValue("p").trim());
            } catch (NumberFormatException e) {
            }
            argsOptions += 2;
        }

    } catch (ParseException e) {
        Common.errorExit(e, "Error while parsing command line arguments: " + e.getMessage());
    }

    if (arguments.size() != argsOptions + 3) {
        help(options);
    }

    // Get the command line arguments
    final String paramPathname = convertS3URL(arguments.get(argsOptions));
    final String designPathname = convertS3URL(arguments.get(argsOptions + 1));
    final String destPathname = convertS3URL(arguments.get(argsOptions + 2));

    // Execute program in hadoop mode
    run(paramPathname, designPathname, destPathname, jobDescription, jobEnvironment, millisSinceEpoch);

}

From source file:com.clustercontrol.maintenance.dialog.HinemosPropertyDialog.java

/**
 * ?????//w w  w.  ja v  a 2  s  . co m
 *
 * @return true?false
 *
 * @see com.clustercontrol.dialog.CommonDialog#action()
 */
@Override
protected boolean action() {
    boolean result = false;

    if (HinemosPropertyInfo == null) {
        this.HinemosPropertyInfo = new HinemosPropertyInfo();
    }
    HinemosPropertyInfo.setKey(m_key.getText());
    HinemosPropertyInfo.setValueType(valueType);

    if (valueType == HinemosPropertyTypeConstant.TYPE_STRING) {
        HinemosPropertyInfo.setValueString(m_value.getText());
    } else if (valueType == HinemosPropertyTypeConstant.TYPE_NUMERIC) {
        if (m_value.getText() == null || m_value.getText().trim().length() == 0) {
            HinemosPropertyInfo.setValueNumeric(null);
        } else {
            try {
                HinemosPropertyInfo.setValueNumeric(Long.parseLong(m_value.getText().trim()));
            } catch (NumberFormatException e) {
                m_log.info("action() setValueNumeric, " + e.getMessage());
                Object[] args = { Messages.getString("hinemos.property.value"), Long.MIN_VALUE,
                        Long.MAX_VALUE };
                MessageDialog.openError(null, Messages.getString("failed"),
                        Messages.getString("message.common.4", args));

                return false;
            }
        }
    } else {
        HinemosPropertyInfo.setValueBoolean(Boolean.parseBoolean(m_blCombo.getText()));
    }

    HinemosPropertyInfo.setDescription(m_textDescription.getText());
    HinemosPropertyInfo.setOwnerRoleId(RoleIdConstant.ADMINISTRATORS);

    if (this.mode == PropertyDefineConstant.MODE_ADD) {
        // ???
        String managerName = this.m_managerComposite.getText();
        String[] args = { HinemosPropertyInfo.getKey(), managerName };
        try {
            HinemosPropertyEndpointWrapper wrapper = HinemosPropertyEndpointWrapper.getWrapper(managerName);
            wrapper.addHinemosProperty(HinemosPropertyInfo);
            MessageDialog.openInformation(null, Messages.getString("successful"),
                    Messages.getString("message.hinemos.property.2", args));

            result = true;
        } catch (HinemosPropertyDuplicate_Exception e) {
            // ????????
            MessageDialog.openInformation(null, Messages.getString("message"),
                    Messages.getString("message.hinemos.property.10", args));
        } catch (Exception e) {
            String errMessage = "";
            if (e instanceof InvalidRole_Exception) {
                MessageDialog.openInformation(null, Messages.getString("message"),
                        Messages.getString("message.accesscontrol.16"));
            } else {
                errMessage = ", " + HinemosMessage.replace(e.getMessage());
            }
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.hinemos.property.3", args) + errMessage);
        }

    } else if (this.mode == PropertyDefineConstant.MODE_MODIFY) {
        // ??
        result = new ModifyHinemosProperty().modify(m_managerComposite.getText(), HinemosPropertyInfo);
    }

    return result;
}

From source file:org.exist.xquery.modules.jfreechart.Configuration.java

/**
 *  Parse text and return Integer. NULL is returned when value
 * cannot be converted./* w  ww  .ja v a  2  s.c  om*/
 */
private Integer parseInteger(String value) {

    try {
        return Integer.valueOf(value);

    } catch (NumberFormatException ex) {
        logger.debug(ex.getMessage());
    }
    return null;
}

From source file:org.exist.xquery.modules.jfreechart.Configuration.java

/**
 *  Parse text and return Double. NULL is returned when value
 * cannot be converted./*from ww w. j  av  a  2  s.  com*/
 */
private Double parseDouble(String value) {

    try {
        return Double.valueOf(value);

    } catch (NumberFormatException ex) {
        logger.debug(ex.getMessage());
    }
    return null;
}

From source file:org.yamj.core.service.metadata.online.TheTVDbScanner.java

@Override
public ScanResult scan(Series series) {
    com.omertron.thetvdbapi.model.Series tvdbSeries = null;
    List<Actor> tvdbActors = null;
    try {/*  w w w.  j ava  2s  . co  m*/
        boolean throwTempError = configServiceWrapper.getBooleanProperty("thetvdb.throwError.tempUnavailable",
                Boolean.TRUE);
        String tvdbId = getSeriesId(series, throwTempError);

        if (StringUtils.isBlank(tvdbId)) {
            LOG.debug("TVDb id not available '{}'", series.getTitle());
            return ScanResult.MISSING_ID;
        }

        tvdbSeries = tvdbApiWrapper.getSeries(tvdbId, throwTempError);
        tvdbActors = tvdbApiWrapper.getActors(tvdbSeries.getId(), throwTempError);
    } catch (TemporaryUnavailableException ex) {
        // check retry
        int maxRetries = this.configServiceWrapper.getIntProperty("thetvdb.maxRetries.tvshow", 0);
        if (series.getRetries() < maxRetries) {
            return ScanResult.RETRY;
        }
    }

    if (tvdbSeries == null || StringUtils.isBlank(tvdbSeries.getId()) || tvdbActors == null) {
        LOG.error("Can't find informations for series '{}'", series.getTitle());
        return ScanResult.ERROR;
    }

    series.setSourceDbId(SCANNER_ID, tvdbSeries.getId());
    series.setSourceDbId(ImdbScanner.SCANNER_ID, tvdbSeries.getImdbId());

    if (OverrideTools.checkOverwriteTitle(series, SCANNER_ID)) {
        series.setTitle(tvdbSeries.getSeriesName(), SCANNER_ID);
    }

    if (OverrideTools.checkOverwritePlot(series, SCANNER_ID)) {
        series.setPlot(tvdbSeries.getOverview(), SCANNER_ID);
    }

    if (OverrideTools.checkOverwriteOutline(series, SCANNER_ID)) {
        series.setOutline(tvdbSeries.getOverview(), SCANNER_ID);
    }

    if (StringUtils.isNumeric(tvdbSeries.getRating())) {
        try {
            series.addRating(SCANNER_ID, (int) (Float.parseFloat(tvdbSeries.getRating()) * 10));
        } catch (NumberFormatException nfe) {
            LOG.warn("Failed to convert TVDB rating '{}' to an integer: {}", tvdbSeries.getRating(),
                    nfe.getMessage());
        }
    }

    if (OverrideTools.checkOverwriteYear(series, SCANNER_ID)) {
        String faDate = tvdbSeries.getFirstAired();
        if (StringUtils.isNotBlank(faDate) && (faDate.length() >= 4)) {
            try {
                series.setStartYear(Integer.parseInt(faDate.substring(0, 4)), SCANNER_ID);
            } catch (Exception ignore) {
                // ignore error if year is invalid
            }
        }
    }

    if (OverrideTools.checkOverwriteGenres(series, SCANNER_ID)) {
        series.setGenreNames(new LinkedHashSet<>(tvdbSeries.getGenres()), SCANNER_ID);
    }

    if (OverrideTools.checkOverwriteStudios(series, SCANNER_ID)) {
        String studioName = StringUtils.trimToNull(tvdbSeries.getNetwork());
        if (studioName != null) {
            Set<String> studioNames = Collections.singleton(studioName);
            series.setStudioNames(studioNames, SCANNER_ID);
        }
    }

    // CAST & CREW
    Set<CreditDTO> actors = new LinkedHashSet<>();
    if (this.configServiceWrapper.isCastScanEnabled(JobType.ACTOR)) {
        for (Actor actor : tvdbActors) {
            actors.add(new CreditDTO(SCANNER_ID, JobType.ACTOR, actor.getName(), actor.getRole()));
        }
    }

    // SCAN SEASONS
    this.scanSeasons(series, tvdbSeries, actors);

    return ScanResult.OK;
}

From source file:cz.incad.kramerius.rest.api.k5.client.search.SearchResource.java

private String checkHighlightValues(String v, String value) {
    if (v.equals("hl.fragsize")) {
        try {/*from  w w  w .java2s  .c  om*/
            int confVal = KConfiguration.getInstance().getConfiguration()
                    .getInt("api.search.highlight.defaultfragsize", 20);
            int maxVal = KConfiguration.getInstance().getConfiguration()
                    .getInt("api.search.highlight.maxfragsize", 120);
            int val = Integer.parseInt(value);
            if (val == 0) {
                val = confVal;
            } else if (val > maxVal) {
                val = confVal;
            }
            return "" + val;
        } catch (NumberFormatException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            return value;
        }
    } else {
        return value;
    }
}

From source file:DateParser.java

/**
 * Check if a given date is an iso8601 date.
 * //from  ww w  . j  av a 2s. c  o m
 * @param iso8601Date The date to be checked.
 * @return <code>true</code> if the date is an iso8601 date.
 * @throws InvalidDateException 
 */
private Calendar getCalendar(String iso8601Date) throws InvalidDateException {
    // YYYY-MM-DDThh:mm:ss.sTZD
    StringTokenizer st = new StringTokenizer(iso8601Date, "-T:.+Z", true);
    if (!st.hasMoreTokens()) {
        throw new InvalidDateException("Empty Date");
    }
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.clear();
    try {
        // Year
        if (st.hasMoreTokens()) {
            int year = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.YEAR, year);
        } else {
            return calendar;
        }
        // Month
        if (checkValueAndNext(st, "-")) {
            int month = Integer.parseInt(st.nextToken()) - 1;
            calendar.set(Calendar.MONTH, month);
        } else {
            return calendar;
        }
        // Day
        if (checkValueAndNext(st, "-")) {
            int day = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.DAY_OF_MONTH, day);
        } else {
            return calendar;
        }
        // Hour
        if (checkValueAndNext(st, "T")) {
            int hour = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.HOUR_OF_DAY, hour);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        // Minutes
        if (checkValueAndNext(st, ":")) {
            int minutes = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.MINUTE, minutes);
        } else {
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        if (!st.hasMoreTokens()) {
            return calendar;
        }
        // Not mandatory now
        // Seconds
        String tok = st.nextToken();
        if (tok.equals(":")) { // seconds
            if (st.hasMoreTokens()) {
                int secondes = Integer.parseInt(st.nextToken());
                calendar.set(Calendar.SECOND, secondes);
                if (!st.hasMoreTokens()) {
                    return calendar;
                }
                // decimal fraction of a second
                tok = st.nextToken();
                if (tok.equals(".")) {
                    String nt = st.nextToken();
                    while (nt.length() < 3) {
                        nt += "0";
                    }
                    if (nt.length() > 3) {
                        // check the other part from the decimal fraction to be formed only from digits
                        for (int i = 3; i < nt.length(); i++) {
                            if (!Character.isDigit(nt.charAt(i))) {
                                throw new InvalidDateException(
                                        "Invalid digit in the decimal fraction of a second: " + nt.charAt(i));
                            }
                        }
                    }
                    nt = nt.substring(0, 3); //Cut trailing chars..
                    int millisec = Integer.parseInt(nt);
                    calendar.set(Calendar.MILLISECOND, millisec);
                    if (!st.hasMoreTokens()) {
                        return calendar;
                    }
                    tok = st.nextToken();
                } else {
                    calendar.set(Calendar.MILLISECOND, 0);
                }
            } else {
                throw new InvalidDateException("No secondes specified");
            }
        } else {
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        }
        // Time zone
        if (!tok.equals("Z")) { // UTC
            if (!(tok.equals("+") || tok.equals("-"))) {
                throw new InvalidDateException("only Z, + or - allowed");
            }
            boolean plus = tok.equals("+");
            if (!st.hasMoreTokens()) {
                throw new InvalidDateException("Missing hour field");
            }
            int tzhour = Integer.parseInt(st.nextToken());
            int tzmin = 0;
            if (checkValueAndNext(st, ":")) {
                tzmin = Integer.parseInt(st.nextToken());
            } else {
                throw new InvalidDateException("Missing minute field");
            }
            if (plus) {
                calendar.add(Calendar.HOUR, -tzhour);
                calendar.add(Calendar.MINUTE, -tzmin);
            } else {
                calendar.add(Calendar.HOUR, tzhour);
                calendar.add(Calendar.MINUTE, tzmin);
            }
        } else {
            if (st.hasMoreTokens()) {
                throw new InvalidDateException(
                        "Unexpected field at the end of the date field: " + st.nextToken());
            }
        }
    } catch (NumberFormatException ex) {
        throw new InvalidDateException("[" + ex.getMessage() + "] is not an integer");
    }
    return calendar;
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

private void loadLayoutSettings(DesktopThemeImpl theme, Element element) {
    try {/*from ww w. j av  a  2 s  .c  o  m*/
        String margin = element.attributeValue("margin-size");
        if (margin != null) {
            theme.setMarginSize(Integer.valueOf(margin));
        }

        String spacing = element.attributeValue("spacing-size");
        if (spacing != null) {
            theme.setSpacingSize(Integer.valueOf(spacing));
        }
    } catch (NumberFormatException e) {
        log.error("Invalid integer value at layout settings: " + e.getMessage());
    }
}