Example usage for java.lang NumberFormatException getLocalizedMessage

List of usage examples for java.lang NumberFormatException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:dev.ukanth.ufirewall.Api.java

private static boolean importAll(Context ctx, File file, StringBuilder msg) {
    boolean returnVal = false;
    BufferedReader br = null;/*from   w  ww .j a  v a2 s  . c o m*/

    try {
        StringBuilder text = new StringBuilder();
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            text.append(line);
        }
        String data = text.toString();
        JSONObject object = new JSONObject(data);
        String[] ignore = { "appVersion", "fixLeak", "enableLogService", "enableLog" };
        List<String> ignoreList = Arrays.asList(ignore);
        JSONArray prefArray = (JSONArray) object.get("prefs");
        for (int i = 0; i < prefArray.length(); i++) {
            JSONObject prefObj = (JSONObject) prefArray.get(i);
            Iterator<?> keys = prefObj.keys();

            while (keys.hasNext()) {
                String key = (String) keys.next();
                String value = (String) prefObj.get(key);
                if (!ignoreList.contains(key)) {
                    //boolean type values
                    if (value.equals("true") || value.equals("false")) {
                        G.gPrefs.edit().putBoolean(key, Boolean.parseBoolean(value)).commit();
                    } else {
                        try {
                            //handle Long
                            if (key.equals("multiUserId")) {
                                G.gPrefs.edit().putLong(key, Long.parseLong(value)).commit();
                            } else if (key.equals("patternMax")) {
                                G.gPrefs.edit().putString(key, value).commit();
                            } else {
                                Integer intValue = Integer.parseInt(value);
                                G.gPrefs.edit().putInt(key, intValue).commit();
                            }
                        } catch (NumberFormatException e) {
                            G.gPrefs.edit().putString(key, value).commit();
                        }
                    }
                }
            }
        }
        if (G.enableMultiProfile()) {
            JSONObject profileObject = object.getJSONObject("profiles");
            Iterator<?> keys = profileObject.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (!key.equals(PREFS_NAME)) {
                    updateRulesFromJson(ctx, profileObject.getJSONObject(key), key);
                }
            }
            //handle custom/additional profiles
            JSONObject customProfileObject = object.getJSONObject("additional_profiles");
            keys = customProfileObject.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                updateRulesFromJson(ctx, profileObject.getJSONObject(key), key);
            }

        } else {
            //now restore the default profile
            JSONObject defaultRules = object.getJSONObject("default");
            updateRulesFromJson(ctx, defaultRules, PREFS_NAME);
        }
        returnVal = true;
    } catch (FileNotFoundException e) {
        msg.append(ctx.getString(R.string.import_rules_missing));
    } catch (IOException e) {
        Log.e(TAG, e.getLocalizedMessage());
    } catch (JSONException e) {
        Log.e(TAG, e.getLocalizedMessage());
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }
        }
    }
    return returnVal;
}

From source file:org.ejbca.ui.web.admin.rainterface.RAInterfaceBean.java

public String importProfilesFromZip(byte[] filebuffer) {
    if (log.isTraceEnabled()) {
        log.trace(">importProfiles(): " + importedProfileName + " - " + filebuffer.length + " bytes");
    }//from   w  w  w  .j  a va  2  s. co  m

    String retmsg = "";
    String faultXMLmsg = "";

    if (StringUtils.isEmpty(importedProfileName) || filebuffer.length == 0) {
        retmsg = "Error: No input file";
        log.error(retmsg);
        return retmsg;
    }

    int importedFiles = 0;
    int ignoredFiles = 0;
    int nrOfFiles = 0;
    try {
        ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(filebuffer));
        ZipEntry ze = zis.getNextEntry();
        if (ze == null) {
            retmsg = "Error: Expected a zip file. '" + importedProfileName + "' is not a  zip file.";
            log.error(retmsg);
            return retmsg;
        }

        do {
            nrOfFiles++;
            String filename = ze.getName();
            if (log.isDebugEnabled()) {
                log.debug("Importing file: " + filename);
            }

            if (ignoreFile(filename)) {
                ignoredFiles++;
                continue;
            }

            String profilename;
            filename = URLDecoder.decode(filename, "UTF-8");

            int index1 = filename.indexOf("_");
            int index2 = filename.lastIndexOf("-");
            int index3 = filename.lastIndexOf(".xml");
            profilename = filename.substring(index1 + 1, index2);
            int profileid = 0;
            try {
                profileid = Integer.parseInt(filename.substring(index2 + 1, index3));
            } catch (NumberFormatException e) {
                if (log.isDebugEnabled()) {
                    log.debug("NumberFormatException parsing certificate profile id: " + e.getMessage());
                }
                ignoredFiles++;
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("Extracted profile name '" + profilename + "' and profile ID '" + profileid + "'");
            }

            if (ignoreProfile(filename, profilename, profileid)) {
                ignoredFiles++;
                continue;
            }

            if (endEntityProfileSession.getEndEntityProfile(profileid) != null) {
                int newprofileid = endEntityProfileSession.findFreeEndEntityProfileId();
                log.warn("Entity profileid '" + profileid + "' already exist in database. Using " + newprofileid
                        + " instead.");
                profileid = newprofileid;
            }

            byte[] filebytes = new byte[102400];
            int i = 0;
            while ((zis.available() == 1) && (i < filebytes.length)) {
                filebytes[i++] = (byte) zis.read();
            }

            EndEntityProfile eprofile = getEEProfileFromByteArray(profilename, filebytes);
            if (eprofile == null) {
                String msg = "Faulty XML file '" + filename + "'. Failed to read End Entity Profile.";
                log.info(msg + " Ignoring file.");
                ignoredFiles++;
                faultXMLmsg += filename + ", ";
                continue;
            }

            profiles.addEndEntityProfile(profilename, eprofile);
            importedFiles++;
            log.info("Added EndEntity profile: " + profilename);

        } while ((ze = zis.getNextEntry()) != null);
        zis.closeEntry();
        zis.close();
    } catch (UnsupportedEncodingException e) {
        retmsg = "Error: UTF-8 was not a known character encoding.";
        log.error(retmsg, e);
        return retmsg;
    } catch (IOException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    } catch (AuthorizationDeniedException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    } catch (EndEntityProfileExistsException e) {
        log.error(e);
        retmsg = "Error: " + e.getLocalizedMessage();
        return retmsg;
    }

    if (StringUtils.isNotEmpty(faultXMLmsg)) {
        faultXMLmsg = faultXMLmsg.substring(0, faultXMLmsg.length() - 2);
        retmsg = "Faulty XML files: " + faultXMLmsg + ". " + importedFiles + " profiles were imported.";
    } else {
        retmsg = importedProfileName + " contained " + nrOfFiles + " files. " + importedFiles
                + " EndEntity Profiles were imported and " + ignoredFiles + " files  were ignored.";
    }
    log.info(retmsg);

    return retmsg;
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String RegisterTheDevice(String sSrvr, String sPort, String sData) {
    String sRet = "";
    String line = "";

    //        Debug.waitForDebugger();

    if (sSrvr != null && sPort != null && sData != null) {
        try {//from ww w  .ja  va2 s . c  om
            int nPort = Integer.parseInt(sPort);
            Socket socket = new Socket(sSrvr, nPort);
            PrintWriter out = new PrintWriter(socket.getOutputStream(), false);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out.println(sData);
            if (out.checkError() == false) {
                socket.setSoTimeout(30000);
                while (socket.isInputShutdown() == false) {
                    line = in.readLine();

                    if (line != null) {
                        line = line.toLowerCase();
                        sRet += line;
                        // ok means we're done
                        if (line.contains("ok"))
                            break;
                    } else {
                        // end of stream reached
                        break;
                    }
                }
            }
            out.close();
            in.close();
            socket.close();
        } catch (NumberFormatException e) {
            sRet += "reg NumberFormatException thrown [" + e.getLocalizedMessage() + "]";
            e.printStackTrace();
        } catch (UnknownHostException e) {
            sRet += "reg UnknownHostException thrown [" + e.getLocalizedMessage() + "]";
            e.printStackTrace();
        } catch (IOException e) {
            sRet += "reg IOException thrown [" + e.getLocalizedMessage() + "]";
            e.printStackTrace();
        }
    }
    return (sRet);
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeReader.java

public void read(final File polyFile) throws IOException {
    LineNumberReader reader = null;
    try {//from w  w  w. j av  a 2  s  .co m
        reader = new LineNumberReader(new FileReader(polyFile));

        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            final String trimmedLine = line.trim().replaceAll(" \\(h\\)", "\\(h\\)"); //$NON-NLS-1$ //$NON-NLS-2$
            final String[] tokens = trimmedLine.split(" +"); //$NON-NLS-1$
            if (tokens.length < 8)
                continue;

            /* Determine if this is a good line: good lines are lines whos first token is a number */
            final BigDecimal station;
            try {
                station = new BigDecimal(tokens[0]);
            } catch (final NumberFormatException nfe) {
                /* Just ignore this line */
                continue;
            }

            try {
                final String description = tokens[1];
                // final String whatIsN = tokens[2];
                final char type = tokens[3].charAt(0);

                final int order = Integer.parseInt(tokens[4]);
                final double rangeMin = Double.parseDouble(tokens[5].replace('D', 'E'));
                final double rangeMax = Double.parseDouble(tokens[6].replace('D', 'E'));

                if (tokens.length < 7 + order + 1) {
                    /* A good line but bad content. Give user a hint that something might be wrong. */
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.22"), //$NON-NLS-1$
                            polyFile.getName(), reader.getLineNumber());
                    continue;
                }

                final List<Double> coefficients = new ArrayList<>(order);
                for (int i = 7; i < 7 + order + 1; i++) {
                    final double coeff = Double.parseDouble(tokens[i].replace('D', 'E'));
                    coefficients.add(coeff);
                }

                final Double[] doubles = coefficients.toArray(new Double[coefficients.size()]);
                final double[] coeffDoubles = ArrayUtils.toPrimitive(doubles);

                final String domainId;
                final String rangeId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_WATERLEVEL;
                switch (type) {
                case 'Q':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_RUNOFF;
                    break;
                case 'A':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_AREA;
                    break;
                case 'a':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_ALPHA;
                    break;

                default:
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.23"), //$NON-NLS-1$
                            station);
                    continue;
                }

                /* find feature for station */
                final QIntervallResult qresult = m_intervalIndex.get(station);
                if (qresult == null)
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.24"), //$NON-NLS-1$
                            station, line);
                else {
                    /* create new polynome */
                    final IPolynomial1D poly1d = qresult.createPolynomial();

                    poly1d.setName(description);
                    poly1d.setDescription(description);
                    poly1d.setCoefficients(coeffDoubles);
                    poly1d.setRange(rangeMin, rangeMax);

                    poly1d.setDomainPhenomenon(domainId);
                    poly1d.setRangePhenomenon(rangeId);
                }
            } catch (final NumberFormatException nfe) {
                /* A good line but bad content. Give user a hint that something might be wrong. */
                m_log.log(false,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        polyFile.getName(), reader.getLineNumber(), nfe.getLocalizedMessage());
            } catch (final Exception e) {
                // should never happen
                m_log.log(e,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        polyFile.getName(), reader.getLineNumber(), e.getLocalizedMessage());
            }
        }
        reader.close();
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:de.anderdonau.spacetrader.Main.java

@SuppressWarnings("UnusedParameters")
public void btnShipyardBuyFuel(View view) {
    Popup popup;/*from   www  .ja va2 s. c o  m*/
    popup = new Popup(this, "Buy Fuel", "How much do you want to spend maximally on fuel?", "Credits",
            "Enter the amount of credits you wish to spend on fuel and tap OK. Your fuel tank will be filled with as much fuel as you can buy with that amount of credits.",
            gameState.Credits, "Buy fuel", "Don't buy fuel", new Popup.buttonCallback() {
                @Override
                public void execute(Popup popup, View view) {
                    SeekBar seekBar = (SeekBar) view;
                    try {
                        int amount = seekBar.getProgress();
                        btnShipyardBuyFuel(amount);
                    } catch (NumberFormatException e) {
                        Popup popup1 = new Popup(popup.context, "Error", e.getLocalizedMessage(), "", "OK",
                                cbShowNextPopup);
                        popupQueue.push(popup1);
                    }
                }
            }, cbShowNextPopup, new Popup.buttonCallback() {
                @Override
                public void execute(Popup popup, View view) {
                    btnShipyardBuyMaxFuel(null);
                }
            });
    popupQueue.push(popup);
    showNextPopup();
}