Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.normsstuff.maps4norm.Util.java

/**
 * Replaces the current points on the map with the one from the provided
 * file/*from   ww w  . j a  va2 s . c  o  m*/
 *
 * @param f the file to read from
 * @param m the Map activity to add the new points to
 * @throws IOException
 */
static List<LatLng> loadFromFile(final Uri f, final MyMapActivity m) throws IOException {
    List<LatLng> list = new LinkedList<LatLng>();
    BufferedReader in = new BufferedReader(new InputStreamReader(m.getContentResolver().openInputStream(f)));
    String line;
    String[] data;
    while ((line = in.readLine()) != null) {
        data = line.split(";");
        try {
            list.add(new LatLng(Double.parseDouble(data[0]), Double.parseDouble(data[1])));
        } catch (NumberFormatException nfe) {
            // should not happen when opening a valid file
            nfe.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException aiabe) {
            // should not happen when opening a valid file
            aiabe.printStackTrace();
        }
    }
    in.close();
    return list;
    /*        
            m.clearDM();
            for (int i = 0; i < list.size(); i++) {
    m.addPoint(list.get(i));
            }
    */
}

From source file:org.kalypso.wspwin.core.WspWinZustand.java

private static ZustandSegmentBean[] readZustandSegments(final LineNumberReader reader, final int segmentCount,
        final String filename) throws ParseException, IOException {
    final List<ZustandSegmentBean> beans = new ArrayList<>(20);

    int readSegments = 0;
    while (reader.ready()) {
        final String line = reader.readLine();
        /* Skip empty lines; we have WspWin projects with and without a separating empty line */
        if (StringUtils.isBlank(line))
            continue;

        final StringTokenizer tokenizer = new StringTokenizer(line);
        if (tokenizer.countTokens() != 7)
            throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.2", filename, //$NON-NLS-1$
                    reader.getLineNumber()), reader.getLineNumber());

        try {// ww  w  . j  a  va  2 s  . c o  m
            final BigDecimal stationFrom = new BigDecimal(tokenizer.nextToken());
            final BigDecimal stationTo = new BigDecimal(tokenizer.nextToken());
            final double distanceVL = Double.parseDouble(tokenizer.nextToken());
            final double distanceHF = Double.parseDouble(tokenizer.nextToken());
            final double distanceVR = Double.parseDouble(tokenizer.nextToken());

            final String fileNameFrom = tokenizer.nextToken();
            final String fileNameTo = tokenizer.nextToken();

            final ZustandSegmentBean bean = new ZustandSegmentBean(stationFrom, stationTo, fileNameFrom,
                    fileNameTo, distanceVL, distanceHF, distanceVR);
            beans.add(bean);

            readSegments++;
        } catch (final NumberFormatException e) {
            e.printStackTrace();
            throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.3", filename, //$NON-NLS-1$
                    reader.getLineNumber()), reader.getLineNumber());
        }
    }

    if (readSegments != segmentCount)
        throw new ParseException(
                Messages.getString("org.kalypso.wspwin.core.WspWinZustand.1", filename, reader.getLineNumber()), //$NON-NLS-1$
                reader.getLineNumber());

    return beans.toArray(new ZustandSegmentBean[beans.size()]);
}

From source file:org.kalypso.model.wspm.core.imports.ImportTrippleHelper.java

/**
 * Imports the profile trippel data and converts it into IProfils
 * //  ww w  .j a v a 2  s .  com
 * @param trippleFile
 *          file with profile tripples
 */
public static IProfile[] importTrippelData(final File trippleFile, final String separator,
        final String profileType, final String crs) throws CoreException {
    final IProfilePointPropertyProvider provider = KalypsoModelWspmCoreExtensions
            .getPointPropertyProviders(profileType);

    final IComponent rechtswert = provider.getPointProperty(IWspmPointProperties.POINT_PROPERTY_RECHTSWERT);
    final IComponent hochwert = provider.getPointProperty(IWspmPointProperties.POINT_PROPERTY_HOCHWERT);

    if (trippleFile == null)
        return new IProfile[0];

    /* read profiles, show warnings */
    final List<IProfile> profiles = new ArrayList<>();
    IProfile currentProfile = null;

    /* file loading */
    LineNumberReader fileReader = null;

    try (InputStreamReader inputReader = new InputStreamReader(new FileInputStream(trippleFile))) {
        fileReader = new LineNumberReader(inputReader);

        /* File Header */
        fileReader.readLine();

        IProfileRecord lastPoint = null;
        while (fileReader.ready()) {
            final String line = fileReader.readLine();
            if (line == null) {
                break;
            }

            /* ignore empty lines */
            if (StringUtils.isBlank(line)) {
                continue;
            }

            /* trippel-format should be: station, x, y, z */
            final String[] tokens = StringUtils.split(line, separator);

            /* continue just if there are enough values in the trippel file */
            if (tokens.length != 4) {
                // FIXME: better error handling
                // inform the user that his profile has not enough values...
                final String message = Messages.getString(
                        "org.kalypso.model.wspm.core.imports.ImportTrippleHelper.0", //$NON-NLS-1$
                        fileReader.getLineNumber());
                final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message);
                throw new CoreException(status);
            }

            try {
                /* first value = profile station */
                final double station = NumberUtils.parseDouble(tokens[0]);
                final BigDecimal currentStation = ProfileUtil.stationToBigDecimal(station);

                final BigDecimal currentProfileStation = currentProfile == null ? null
                        : ProfileUtil.stationToBigDecimal(currentProfile.getStation());

                if (!ObjectUtils.equals(currentStation, currentProfileStation)) {
                    lastPoint = null;

                    currentProfile = ProfileFactory.createProfil(profileType, null);

                    currentProfile.setStation(station);
                    currentProfile.setName(
                            Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.1")); //$NON-NLS-1$
                    currentProfile.setDescription(
                            Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.2")); //$NON-NLS-1$
                    currentProfile.setSrsName(crs);

                    currentProfile.addPointProperty(rechtswert);
                    currentProfile.addPointProperty(hochwert);

                    profiles.add(currentProfile);
                }

                final IProfileRecord point = ImportTrippleHelper.createProfilePoint(currentProfile, tokens,
                        lastPoint);
                if (point != null) {
                    currentProfile.addPoint(point);
                }

                lastPoint = point;
            } catch (final NumberFormatException e) {
                e.printStackTrace();
                final String message = Messages.getString(
                        "org.kalypso.model.wspm.core.imports.ImportTrippleHelper.3", //$NON-NLS-1$
                        fileReader.getLineNumber());
                final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message,
                        e);
                throw new CoreException(status);
            }
        }

        fileReader.close();
    } catch (final IOException e) {
        e.printStackTrace();

        final int lineNumber = fileReader == null ? 0 : fileReader.getLineNumber();

        final String message = Messages.getString("org.kalypso.model.wspm.core.imports.ImportTrippleHelper.4", //$NON-NLS-1$
                lineNumber);
        final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message, e);
        throw new CoreException(status);
    }

    return profiles.toArray(new IProfile[profiles.size()]);
}

From source file:com.denimgroup.threadfix.importer.cli.ScriptRunner.java

private static String fixLongColumnStatement(String preLine, String currentLine, Map map) {
    String colName = getColName(currentLine, "Data too long for column '(.*)' at");
    String colDef = getColDef(colName, (String) map.get("tableName"));
    if (colDef != null) {
        String noOfChar = RegexUtils.getRegexResult(colDef, colName.toUpperCase() + " VARCHAR\\((.*)\\)");
        if (noOfChar != null && !noOfChar.isEmpty()) {
            try {
                int noOfCharInt = Integer.parseInt(noOfChar);
                Map<String, String> fieldMap = (Map) map.get("tableFields");
                String oldValue = fieldMap.get(colName.toUpperCase());
                boolean isString = false;
                if (oldValue.startsWith("'") && oldValue.endsWith("'")) {
                    isString = true;//from  ww  w .ja  va  2 s  .  c  o m
                    oldValue = oldValue.substring(1);
                    oldValue = oldValue.substring(0, oldValue.length() - 1);
                }
                oldValue = oldValue.substring(0, noOfCharInt);
                if (isString)
                    oldValue = "'" + oldValue + "'";

                String colList = "";
                String colValues = "";
                for (String key : fieldMap.keySet()) {
                    if (!key.equalsIgnoreCase(colName)) {
                        colList = colList + key + ",";
                        colValues = colValues + fieldMap.get(key) + ",";
                    }
                }
                colList = colList + colName.toUpperCase();
                colValues = colValues + oldValue;
                String fixedStatement = "INSERT INTO " + map.get("tableName") + "(" + colList + ") VALUES" + "("
                        + colValues + ")" + ";\n";
                return fixedStatement;

            } catch (NumberFormatException exp) {
                exp.printStackTrace();
            }
        } else {
            LOGGER.error("Couldn't find column definition");
        }
    }
    LOGGER.error("Unable to fix " + preLine);
    String fixedStatement = preLine.replace("Error executing: ", "");
    return fixedStatement + ";\n";
}

From source file:org.apache.jcs.config.OptionConverter.java

/** Description of the Method
 * @param value/*from  w  ww . j  a v a2 s .c om*/
 * @param dEfault
 * @return
 */
public static int toInt(String value, int dEfault) {
    if (value != null) {
        String s = value.trim();
        try {
            return Integer.valueOf(s).intValue();
        } catch (NumberFormatException e) {
            log.error("[" + s + "] is not in proper int form.");
            e.printStackTrace();
        }
    }
    return dEfault;
}

From source file:control.LoadControler.java

public static Map<String, Integer> loadmainSettings(String filePath) {

    Map<String, Integer> list = new HashMap<>();

    File file = new File(userPath(filePath));

    try {//w  ww.  ja v  a  2s.  c  om
        PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
        Properties properties = ppr.readProperties();

        try {
            Integer nbInitSoldatsParHeros = Integer.parseInt(properties.getProperty("nbInitSoldatsParHeros"));
            Integer xpInit = Integer.parseInt(properties.getProperty("xpInit"));
            Integer popNiveau10 = Integer.parseInt(properties.getProperty("popNiveau10"));

            list.put("nbInitSoldatsParHeros", nbInitSoldatsParHeros);
            list.put("xpInit", xpInit);
            list.put("popNiveau10", popNiveau10);

            System.out.println(list.toString()); //DEBUG

        } catch (NumberFormatException e) {
            e.printStackTrace();
            System.out.println("##### Erreur lors de la lecture des paramtres gnraux #####");
            JOptionPane.showMessageDialog(null, e);
        }

    } catch (IOException ex) {
        Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, ex);
    }

    return list;
}

From source file:it.wami.map.mongodeploy.OsmToMongoDB.java

/**
 * Parse the options passed to the script
 * @param args the options//from   www.jav a2 s  .c om
 */
private static void parseCommandOptions(String[] args) {
    options = new Options();

    for (String arg : args) {

        if (arg.contains(Options.INPUT)) {
            String input = arg.replace(Options.INPUT, "").trim();
            options.setInput(input);
        }
        if (arg.contains(Options.DB)) {
            String dbName = arg.replace(Options.DB, "").trim();
            options.setDbName(dbName);

            System.out.println(dbName);
        }
        if (arg.contains(Options.HOST)) {
            String host = arg.replace(Options.HOST, "").trim();
            options.setHost(host);
        }
        if (arg.contains(Options.PORT)) {
            String temp = arg.replace(Options.PORT, "").trim();
            try {
                int port = Integer.parseInt(temp);
                options.setPort(port);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.exit(0);
            }
        }
        if (arg.contains(Options.UPSERT)) {
            arg.replace(Options.UPSERT, "");
            boolean upsert = Boolean.parseBoolean(arg);
            options.setUpsert(upsert);
        }
        if (arg.contains(Options.OMIT_METADATA)) {
            arg.replace(Options.OMIT_METADATA, "");
            boolean omit_metadata = Boolean.parseBoolean(arg);
            options.setOmit_metadata(omit_metadata);
        }
        if (arg.contains(Options.WG)) {
            boolean wg = true;
            options.setWayGeometry(wg);
        }
        if (arg.contains(Options.RG)) {
            boolean rg = true;
            options.setRelationGeometry(rg);
        }
    }
}

From source file:control.LoadControler.java

public static List<CelluleType> loadCelluleTypes(String filePath) {

    File folder = new File(userPath(filePath));
    Set<File> fileSet = listFilesForFolder(folder);

    List<CelluleType> list = new ArrayList<>();

    for (File file : fileSet) {

        try {//from  www .j  a  v a 2  s. c om
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            CelluleType celluleType = new CelluleType();

            try {
                celluleType.setType(properties.getProperty("nom"));

                System.out.println(celluleType.toString()); //DEBUG
                list.add(celluleType);

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration de la carte #####");
                JOptionPane.showMessageDialog(null, e);
            }
        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return list;
}

From source file:control.LoadControler.java

public static List<Meteo> loadMeteo(String filePath) {

    List<Meteo> list = new ArrayList<>();

    File folder = new File(userPath(filePath));

    Set<File> fileSet = listFilesForFolder(folder);

    for (File file : fileSet) {

        try {//  w w w  .  ja  v a2 s.  c om
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            try {
                Meteo element = new Meteo();
                element.setNom(properties.getProperty("nom"));
                element.setImage(properties.getProperty("image"));
                element.setHandicapCombat(Double.parseDouble(properties.getProperty("handicapCombat")));
                element.setHandicapTir(Double.parseDouble(properties.getProperty("handicapTir")));

                list.add(element);
                System.out.println(element.toString()); //DEBUG

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration d'une meteo #####");
                JOptionPane.showMessageDialog(null, e);
            }

        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return list;
}

From source file:control.LoadControler.java

public static List<Geographie> loadGeographie(String filePath) {

    List<Geographie> list = new ArrayList<>();

    File folder = new File(userPath(filePath));

    Set<File> fileSet = listFilesForFolder(folder);

    for (File file : fileSet) {

        try {/*from w w w. j a  v  a  2 s  .  c  o m*/
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            try {
                Geographie element = new Geographie();
                element.setNom(properties.getProperty("nom"));
                element.setImage(properties.getProperty("image"));
                element.setIsCombatable(Boolean.parseBoolean(properties.getProperty("isCombatable")));
                element.setHandicapJ1Tir(Double.parseDouble(properties.getProperty("handicapJ1Tir")));
                element.setHandicapJ2Tir(Double.parseDouble(properties.getProperty("handicapJ2Tir")));

                list.add(element);
                System.out.println(element.toString()); //DEBUG

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration d'une geographie #####");
                JOptionPane.showMessageDialog(null, e);
            }

        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return list;
}