List of usage examples for java.lang NumberFormatException printStackTrace
public void printStackTrace()
From source file:Main.java
public static boolean checkIPAndPort(String ip, String port) { boolean ok = true; Pattern ipPattern = Pattern .compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); if (!ipPattern.matcher(ip).matches()) { ok = false;/*ww w . j a v a 2 s .c o m*/ } int porti = 0; try { porti = Integer.parseInt(port); } catch (NumberFormatException e) { ok = false; e.printStackTrace(); } if (porti < 1 && porti > 65535) { ok = false; } return ok; }
From source file:Main.java
public static void incrementAttributeValue(Node node, String attName, String attValue) { try {//from w w w . j a v a2 s . co m incrementAttributeValue(node, attName, Integer.decode(attValue)); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static int getIntByString(Bundle bundle, String key, int def) { if (bundle == null) return def; String str = bundle.getString(key); if (!TextUtils.isEmpty(str)) { try {//from w w w .j a v a 2 s . c o m return Integer.parseInt(str); } catch (NumberFormatException e) { // TODO: handle exception e.printStackTrace(); } } return def; }
From source file:Main.java
/** * Convert string format date data to whooing date format integer * @param dateStr Date data formatted string like "05/21" * @return Return whooing style integer date like 20121212 otherwise -1 * *//*from w ww . j av a 2 s . co m*/ static public int convertWhooingDate(String dateStr) { String convertDate = dateStr.replace("/", ""); if (convertDate.length() == 3) { convertDate = "0" + convertDate; } Calendar rightNow = Calendar.getInstance(); int year = rightNow.get(Calendar.YEAR); int month = rightNow.get(Calendar.MONTH) + 1; int day = rightNow.get(Calendar.DAY_OF_MONTH); int today = year * 10000 + month * 100 + day; convertDate = year + convertDate; int convertDateInt = 0; try { convertDateInt = Integer.valueOf(convertDate); // In case of receiving message 12/31 on 1 Jan if ((today / 10000) < (convertDateInt / 10000)) { convertDateInt -= 10000; } } catch (NumberFormatException e) { e.printStackTrace(); } //guard wrong date if (convertDateInt < ((year * 10000) + 101)) { convertDateInt = today; } return convertDateInt; }
From source file:Main.java
public static String convertHtmlCode(String line) { StringBuffer sb = new StringBuffer(); int start = 0; boolean flag = false; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == '&' && (i + 1) < line.length() && line.charAt(i + 1) == '#') { flag = true;/* w ww . j av a 2 s. co m*/ start = i; } if (flag) { if (line.charAt(i) == ';') { String tmp = line.substring(start + 2, i); try { int code = Integer.parseInt(tmp); sb.append((char) code); } catch (NumberFormatException e) { e.printStackTrace(); } flag = false; } } else { sb.append(line.charAt(i)); } } return sb.toString(); }
From source file:Main.java
public static String hexToString(String s) { int i = 0;/*from w ww .j av a 2s . c o m*/ StringBuffer buf = new StringBuffer(1000); if (s == null) return ""; // if null we return null (to avoid any errors) while (i <= s.length() - 6) { char c = s.charAt(i); char next = s.charAt(i + 1); if (c == '\\' && (next == 'u' || next == 'U')) { String tmp = s.substring(i + 2, i + 6); try { int code = Integer.parseInt(tmp, 16); char unicode = (char) code; buf.append(unicode); i += 6; } catch (NumberFormatException e) { e.printStackTrace(); buf.append(c); i++; } } else { buf.append(c); i++; } } return buf.toString(); }
From source file:Main.java
/** * /*from ww w . ja va 2s.co m*/ * @param version1 * @param version2 * @return 0 if equals, 1 if version1 > version2, -1 if version1 < version2 */ public static int compareVersion(String version1, String version2) { if (version1 == null || version1.length() == 0 || version1.equals("null") || version1.contains("string") || version2 == null || version2.length() == 0 || version2.equals("null") || version2.contains("string")) { // invalid version, can not compare return 0; } if (version1.equals(version2)) { // version equals return 0; } else { String[] v1 = version1.split("\\."); String[] v2 = version2.split("\\."); int l = v1.length; if (v2.length < l) { l = v2.length; } if (l > 0) { for (int i = 0; i < l; i++) { try { int int1 = Integer.valueOf(v1[i]); int int2 = Integer.valueOf(v2[i]); if (int1 > int2) { return 1; } else if (int1 < int2) { return -1; } } catch (NumberFormatException e) { e.printStackTrace(); if (v1[i].compareToIgnoreCase(v2[i]) < 0) { return -1; } else if (v1[i].compareToIgnoreCase(v2[i]) > 0) { return 1; } } } return 0; } else { // invalid version, can not compare return 0; } } }
From source file:no.kantega.publishing.api.taglibs.photoalbum.PhotoAlbumHelper.java
public static List<Multimedia> getPhotos(PageContext pageContext, int albumId) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String photoalbum = (String) request.getAttribute("photoalbum"); if (albumId == -1 && !StringUtils.isBlank(photoalbum)) { try {//from w w w . j a v a 2 s . c o m albumId = Integer.parseInt(photoalbum); } catch (NumberFormatException e) { e.printStackTrace(); return null; } } if (albumId == -1) return null; List<Multimedia> photos = (List<Multimedia>) request.getAttribute("aksess_photos_" + albumId); if (photos == null) { photos = new ArrayList<>(); try { MultimediaService mediaService = new MultimediaService(request); List<Multimedia> tmp = mediaService.getMultimediaList(albumId); for (Multimedia multimedia : tmp) { if (multimedia.getType() == MultimediaType.MEDIA) { photos.add(multimedia); } } request.setAttribute("aksess_photos_" + albumId, photos); } catch (SystemException e) { log.error("", e); } } return photos; }
From source file:Main.java
public static final Object getObjectValue(String value) { try {// w ww.ja v a 2 s . c om return Long.valueOf(value); } catch (NumberFormatException e) { } try { return Double.valueOf(value); } catch (NumberFormatException e) { e.printStackTrace(); return value; } }
From source file:nightkosh.gravestone.config.ConfigsHelper.java
public static List<Integer> getDimensionList(Configuration config, String category, String ConfigID, String defaultValue, String comment) { Property dimensionIdProperty = config.get(category, ConfigID, defaultValue); dimensionIdProperty.setComment(comment); String ar = dimensionIdProperty.getString(); String[] ids = ar.split(";"); List<Integer> dimensionIds = new ArrayList<>(ids.length); for (String id : ids) { try {/*from w w w . j av a 2s .c om*/ dimensionIds.add(Integer.parseInt(id)); } catch (NumberFormatException e) { GSLogger.logError("Can't parse Dimension Id list!!!"); e.printStackTrace(); } } if (dimensionIds.isEmpty() && StringUtils.isNotBlank(defaultValue)) { try { dimensionIds.add(Integer.parseInt(defaultValue)); } catch (NumberFormatException e) { GSLogger.logError("Can't parse Dimension Id list!!!"); e.printStackTrace(); } } return dimensionIds; }