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:ape.CorruptFileCommand.java

@Override
protected boolean runImpl(String[] args) throws ParseException, IOException {
    String corruptAddress = null;
    corruptAddress = args[0];//  w ww.jav  a2 s . co m
    try {
        size = Integer.parseInt(args[1]);
        offset = Integer.parseInt(args[2]);
    } catch (NumberFormatException t) {
        System.out.println("Unable to parse the size or offset given as an integer.");
        Main.logger.info("Unable to parse the size or offset given as an integer.");
        t.printStackTrace();
        Main.logger.info(t);
        return false;
    }
    if (Main.VERBOSE) {
        System.out.println("address is " + args[0]);
        System.out.println("SIZE is " + size);
        System.out.println("OFFSET is " + offset);
    }
    Main.logger.info("File location is: " + args[0]);
    Main.logger.info("Corruption size is: " + size);
    Main.logger.info("Corruption offset is: " + offset);

    if (!corrupt(corruptAddress)) {
        System.err.println("Error: Corrupting failed.");
        Main.logger.info("Error: Corrupting failed.");
        return false;
    }

    return true;
}

From source file:gov.nih.nci.system.web.struts.action.CreateAction.java

public Object convertValue(Class klass, Object value) throws NumberFormatException, Exception {

    String fieldType = klass.getName();
    if (value == null)
        return null;

    Object convertedValue = null;
    try {//from   ww w .jav a 2 s.c  o m
        if (fieldType.equals("java.lang.Long")) {
            convertedValue = new Long((String) value);
        } else if (fieldType.equals("java.lang.Integer")) {
            convertedValue = new Integer((String) value);
        } else if (fieldType.equals("java.lang.String")) {
            convertedValue = value;
        } else if (fieldType.equals("java.lang.Float")) {
            convertedValue = new Float((String) value);
        } else if (fieldType.equals("java.lang.Double")) {
            convertedValue = new Double((String) value);
        } else if (fieldType.equals("java.lang.Boolean")) {
            convertedValue = new Boolean((String) value);
        } else if (fieldType.equals("java.util.Date")) {
            SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
            convertedValue = format.parse((String) value);
        } else if (fieldType.equals("java.net.URI")) {
            convertedValue = new URI((String) value);
        } else if (fieldType.equals("java.lang.Character")) {
            convertedValue = new Character(((String) value).charAt(0));
        } else if (klass.isEnum()) {
            Class enumKlass = Class.forName(fieldType);
            convertedValue = Enum.valueOf(enumKlass, (String) value);
        } else {
            throw new Exception("type mismatch - " + fieldType);
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
        log.error("ERROR : " + e.getMessage());
        throw e;
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("ERROR : " + ex.getMessage());
        throw ex;
    }
    return convertedValue;
}

From source file:jade.core.messaging.FileMessageStorage.java

private void decrementCounter(File f) throws IOException {

    BufferedReader in = new BufferedReader(new FileReader(f));
    File tmp = File.createTempFile("JADE", ".tmp");
    String s = in.readLine();/*w w w.  j  a  v  a2s.c om*/
    try {
        long counter = Long.parseLong(s);
        counter--;
        if (counter == 0) {
            in.close();
            f.delete();
        } else {
            BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
            try {
                s = Long.toString(counter);
                out.write(s, 0, s.length());
                out.newLine();

                s = in.readLine();
                while (s != null) {
                    out.write(s, 0, s.length());
                    out.newLine();
                    s = in.readLine();
                }
            } finally {
                in.close();
                out.close();
            }

            f.delete();
            tmp.renameTo(f);
        }
    } catch (NumberFormatException nfe) {
        in.close();
        nfe.printStackTrace();
    }

}

From source file:org.kalypso.kalypsosimulationmodel.core.terrainmodel.ASCTerrainElevationModel.java

private void parse(final InputStream inputStream) {
    BufferedReader br = null;/*from w  w w .ja v a2 s . co m*/
    try {
        br = new BufferedReader(new InputStreamReader(inputStream));
        final String[] data = new String[6];
        String line;
        // reading header data
        for (int i = 0; i < 6; i++) {
            line = br.readLine();
            final int index = line.indexOf(" "); //$NON-NLS-1$
            final String subString = line.substring(index);
            data[i] = subString.trim();
        }
        N_COLS = Integer.parseInt(data[0]);
        N_ROWS = Integer.parseInt(data[1]);
        xllcorner = NumberUtils.parseDouble(data[2]);
        yllcorner = NumberUtils.parseDouble(data[3]);
        cellSize = NumberUtils.parseDouble(data[4]);
        final double noDataValue = NumberUtils.parseDouble(data[5]);
        double currentValue;

        elevations = new double[N_ROWS][N_COLS];
        minElevation = Double.MAX_VALUE;
        maxElevation = -Double.MAX_VALUE;

        String[] strRow;
        for (int y = N_ROWS - 1; y >= 0; y--) {
            strRow = br.readLine().trim().split(" "); //$NON-NLS-1$
            for (int x = 0; x < N_COLS; x++) {
                currentValue = NumberUtils.parseDouble(strRow[x]);
                if (currentValue != noDataValue) {
                    elevations[y][x] = currentValue;

                    if (minElevation > currentValue) {
                        minElevation = currentValue;
                    }

                    if (maxElevation < currentValue) {
                        maxElevation = currentValue;
                    }
                } else {
                    elevations[y][x] = Double.NaN;
                }

            }
        }
        maxEnvelope = makeMaxEnvelope();
    } catch (final NumberFormatException e) {
        e.printStackTrace();
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(br);
    }
}

From source file:ilearn.orb.controller.AnnotationController.java

@RequestMapping(value = "/annotation/{userid}", method = RequestMethod.GET)
public ModelAndView textUserAnnotation(Locale locale, ModelMap modelMap, HttpServletRequest request,
        HttpSession session, @PathVariable("userid") Integer userid) {
    try {/* w  ww  .ja  v a2s.  co m*/
        request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    txModule = new TextAnnotationModule();
    ModelAndView model = new ModelAndView();
    model.setViewName("annotation");
    try {
        User[] students = null;
        UserProfile p = null;
        User selectedStudent = null;
        if (userid < 0) {
            students = HardcodedUsers.defaultStudents();
            selectedStudent = selectedStudent(students, userid.intValue());
            // p = HardcodedUsers.defaultProfile(selectedStudent.getId());
            String json = UserServices
                    .getDefaultProfile(HardcodedUsers.defaultProfileLanguage(selectedStudent.getId()));
            if (json != null)
                p = new Gson().fromJson(json, UserProfile.class);
        } else {
            Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateDeserializer())
                    .setDateFormat(DateFormat.LONG).create();
            String json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()),
                    session.getAttribute("auth").toString());
            students = gson.fromJson(json, User[].class);
            selectedStudent = selectedStudent(students, userid.intValue());
            json = UserServices.getJsonProfile(userid, session.getAttribute("auth").toString());
            if (json != null)
                p = new Gson().fromJson(json, UserProfile.class);
        }
        modelMap.put("profileId", userid);
        modelMap.put("selectedStudent", selectedStudent);
        modelMap.put("students", students);
        modelMap.put("selectedProfile", p);

        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader
                .getResource("data/" + (selectedStudent.getLanguage().toLowerCase()) + ".json").getFile());
        String js = LocalStorageTextFileHandler.loadFileAsString(file);
        Groups grps = new Gson().fromJson(js, Groups.class);
        modelMap.put("presents", grps);

    } catch (NumberFormatException e) {
        //e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return model;
}

From source file:com.cloudera.recordservice.tests.MiniClusterController.java

/**
 * This method takes as input a String array of command line arguments in the
 * form --<arg name>=<arg integer value> and inserts them into a
 * Map<ArgName,ArgValue>./* w w w  . j  ava2  s  .co  m*/
 */
private Map<String, Integer> processNodeArgs(String[] args) {
    Map<String, Integer> argTable = new HashMap<String, Integer>();
    if (args == null) {
        return argTable;
    }
    int equalsIndex;
    for (int i = 0; i < args.length; ++i) {
        if (args[i].startsWith("--") && ((equalsIndex = args[i].indexOf("=")) != -1)) {
            String key = args[i].substring(2, equalsIndex);
            try {
                Integer value = Integer.parseInt(args[i].substring(equalsIndex + 1));
                argTable.put(key, value);
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
                continue;
            }
        }
    }
    return argTable;
}

From source file:com.znsx.cms.service.impl.LicenseManagerImpl.java

/**
 * ?//from  w  ww  .  ja v  a2  s. c om
 * 
 * @param license
 *            ?License
 * @throws BusinessException
 * @author huangbuji
 *         <p />
 *         Create at 2013 ?6:57:52
 */
private void userAmountCheck(License license) throws BusinessException {
    int userCount = userDAO.getTotalCount();
    String userAmount = license.getUserAmount();
    try {
        if (Integer.parseInt(userAmount) < userCount) {
            throw new BusinessException(ErrorCode.USER_AMOUNT_LIMIT, "User amount over license limit !");
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.USER_AMOUNT_INVALID,
                "License value user_amount[" + license.getUserAmount() + "] invaild !");
    }
}

From source file:com.znsx.cms.service.impl.LicenseManagerImpl.java

/**
 * ??/*w ww.  j  a v a  2  s .  com*/
 * 
 * @param license
 *            ?License
 * @throws BusinessException
 * @author huangbuji
 *         <p />
 *         Create at 2013 ?7:14:21
 */
private void cameraAmountCheck(License license) throws BusinessException {
    int cameraCount = cameraDAO.getTotalCount();
    String cameraAmount = license.getCameraAmount();
    try {
        if (Integer.parseInt(cameraAmount) < cameraCount) {
            throw new BusinessException(ErrorCode.CAMERA_AMOUNT_LIMIT, "Camera amount over license limit !");
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.CAMERA_AMOUNT_INVALID,
                "License value camera_amount[" + license.getCameraAmount() + "] invaild !");
    }
}

From source file:es.uniovi.imovil.fcrtrainer.TwosComplementExerciseFragment.java

void endGame() {
    super.endGame();
    tex_tittle.setText(R.string.finJuego);
    tex_numberToConvert.setText(getResources().getString(R.string.points01) + calculatePoints()
            + getResources().getString(R.string.points02));
    but_check.setVisibility(View.GONE);
    rel_cards.setVisibility(View.GONE);

    try {/*  www . j a  v  a 2 s.c o  m*/

        HighscoreManager.addScore(getActivity(), points, R.string.twoscomplement, new Date(), null);
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.znsx.cms.service.impl.LicenseManagerImpl.java

/**
 * ??//from   w  ww. jav a  2 s  .c  o m
 * 
 * @param license
 *            ?License
 * @throws BusinessException
 * @author huangbuji
 *         <p />
 *         Create at 2013 ?7:11:28
 */
private void deviceAmountCheck(License license) throws BusinessException {
    // ???
    int deviceCount = snDAO.countDeviceAmount();
    String deviceAmount = license.getDeviceAmount();
    try {
        if (Integer.parseInt(deviceAmount) < deviceCount) {
            throw new BusinessException(ErrorCode.DEVICE_AMOUNT_LIMIT, "Device amount over license limit !");
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        throw new BusinessException(ErrorCode.DEVICE_AMOUNT_INVALID,
                "License value device_amount[" + license.getDeviceAmount() + "] invaild !");
    }
}