List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:com.basetechnology.s0.agentserver.notification.NotificationRecord.java
static public NotificationRecord fromJson(AgentInstance agentInstance, JSONObject notificationRecordJson) throws AgentServerException, SymbolException { int sequenceNumber = notificationRecordJson.optInt("sequence"); String timeString = notificationRecordJson.optString("time", null); long time = -1; try {//from w ww. j av a 2 s .co m time = timeString != null ? DateUtils.parseRfcString(timeString) : -1; } catch (ParseException e) { throw new AgentServerException( "Unable to parse time for notification record: " + timeString + " - " + e.getMessage()); } NotificationInstance notificationInstance = NotificationInstance.fromJson(agentInstance, notificationRecordJson.optJSONObject("notification")); return new NotificationRecord(time, sequenceNumber, notificationInstance); }
From source file:org.codecyprus.android_client.sync.JsonParser.java
public static Category[] parseGetActiveCategories(final String json) throws JSONException, JsonParseException { final Category[] categories = parseGetCategories(json); // filter out finished competitions final SortedSet<Category> activeCategories = new TreeSet<>(); final long now = System.currentTimeMillis(); for (final Category category : categories) { try {/*from w w w. j av a2 s . co m*/ final Date validUntil = CategoriesAdapter.SIMPLE_DATE_FORMAT.parse(category.getValidUntil()); if (now < validUntil.getTime()) { activeCategories.add(category); } } catch (ParseException pe) { Log.e(TAG, pe.getMessage()); } } return activeCategories.toArray(new Category[activeCategories.size()]); }
From source file:com.bitplan.vzjava.resources.PowerPlotResource.java
/** * http://stackoverflow.com/a/10257341/1497139 * Sends the file if modified and "not modified" if not modified * future work may put each file with a unique id in a separate folder in * tomcat// www. ja v a2 s . com * * use that static URL for each file * * if file is modified, URL of file changes * * -> client always fetches correct file * * method header for calling method public Response * getXY(@HeaderParam("If-Modified-Since") String modified) { * * @param file * to send * @param modified * - HeaderField "If-Modified-Since" - may be "null" * @return Response to be sent to the client */ public static Response returnFile(File file, String modified) { if (!file.exists()) { return Response.status(Status.NOT_FOUND).build(); } // do we really need to send the file or can send "not modified"? if (modified != null) { Date modifiedDate = null; // we have to switch the locale to ENGLISH as parseDate parses in the // default locale Locale old = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); try { modifiedDate = DateUtils.parseDate(modified, DEFAULT_PATTERNS); } catch (ParseException e) { LOGGER.log(Level.WARNING, e.getMessage()); } Locale.setDefault(old); if (modifiedDate != null) { // modifiedDate does not carry milliseconds, but fileDate does // therefore we have to do a range-based comparison // 1000 milliseconds = 1 second if (file.lastModified() - modifiedDate.getTime() < DateUtils.MILLIS_PER_SECOND) { return Response.status(Status.NOT_MODIFIED).build(); } } } // we really need to send the file try { Date fileDate = new Date(file.lastModified()); return Response.ok(new FileInputStream(file)).lastModified(fileDate).build(); } catch (FileNotFoundException e) { return Response.status(Status.NOT_FOUND).build(); } }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the given NumberFormat. Trims the input <code>String</code> * before attempting to parse the number. * * @param text the text to convert * @param targetClass the target class to parse into * @param numberFormat the NumberFormat to use for parsing (if <code>null</code>, * this method falls back to <code>parseNumber(String, Class)</code>) * @return the parsed number/*from www . j av a 2 s. c om*/ * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.text.NumberFormat#parse * @see #convertNumberToTargetClass * @see #parseNumber(String,Class) */ public static Number parseNumber(String text, Class targetClass, NumberFormat numberFormat) { if (numberFormat != null) { try { Number number = numberFormat.parse(text.trim()); return convertNumberToTargetClass(number, targetClass); } catch (ParseException ex) { throw new IllegalArgumentException(ex.getMessage()); } } else { return parseNumber(text, targetClass); } }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the given NumberFormat. Trims the input <code>String</code> * before attempting to parse the number. * @param text the text to convert//from w w w . j a va 2 s. c o m * @param targetClass the target class to parse into * @param numberFormat the NumberFormat to use for parsing (if <code>null</code>, * this method falls back to <code>parseNumber(String, Class)</code>) * @return the parsed number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.text.NumberFormat#parse * @see #convertNumberToTargetClass * @see #parseNumber(String, Class) */ public static Number parseNumber(String text, Class targetClass, NumberFormat numberFormat) { if (numberFormat != null) { try { Number number = numberFormat.parse(text.trim()); return convertNumberToTargetClass(number, targetClass); } catch (ParseException ex) { throw new IllegalArgumentException(ex.getMessage()); } } else { return parseNumber(text, targetClass); } }
From source file:com.vangent.hieos.xutil.hl7.date.Hl7Date.java
/** * // ww w. j a v a 2 s. co m * @param inputDTM * @return */ static public Date toDate(String inputDTM) { try { Date date = DateUtils.parseDate(inputDTM, _dtmParsePatterns); return date; } catch (ParseException ex) { // FIXME: Do something? System.out.println("ParseException: " + ex.getMessage()); } return null; }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the given NumberFormat. Trims the input <code>String</code> * before attempting to parse the number. * @param text the text to convert//from ww w .j a va 2 s. co m * @param targetClass the target class to parse into * @param numberFormat the NumberFormat to use for parsing (if <code>null</code>, * this method falls back to <code>parseNumber(String, Class)</code>) * @return the parsed number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.text.NumberFormat#parse * @see #convertNumberToTargetClass * @see #parseNumber(String, Class) */ public static Number parseNumber(String text, Class<?> targetClass, NumberFormat numberFormat) { if (numberFormat != null) { //Assert.notNull(text, "Text must not be null"); // Assert.notNull(targetClass, "Target class must not be null"); try { Number number = numberFormat.parse(text.trim()); return convertNumberToTargetClass(number, targetClass); } catch (ParseException ex) { throw new IllegalArgumentException(ex.getMessage()); } } return parseNumber(text, targetClass); }
From source file:com.ocs.dynamo.utils.DateUtils.java
/** * Creates a java.util.Date based on a string representation * //from w ww .j a v a 2 s. com * @param dateStr * the string (in the format ddMMyyyy) * @return */ public static Date createDate(String dateStr) { if (dateStr == null) { return null; } SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); try { return format.parse(dateStr); } catch (ParseException e) { throw new OCSRuntimeException(e.getMessage(), e); } }
From source file:com.teamsun.framework.util.DateUtil.java
/** * This method generates a string representation of a date/time * in the format you specify on input/*from w ww .ja va 2 s . c om*/ * * @param aMask the date pattern the string is in * @param strDate a string representation of a date * @return a converted Date object * @see java.text.SimpleDateFormat * @throws ParseException */ public static final Date convertStringToDate(String aMask, String strDate) throws ParseException { SimpleDateFormat df = null; Date date = null; df = new SimpleDateFormat(aMask); if (log.isDebugEnabled()) { log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'"); } try { date = df.parse(strDate); } catch (ParseException pe) { //log.error("ParseException: " + pe); throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }
From source file:org.musicrecital.util.DateUtil.java
/** * This method generates a string representation of a date/time * in the format you specify on input// www .j av a2 s . c o m * * @param aMask the date pattern the string is in * @param strDate a string representation of a date * @return a converted Date object * @throws ParseException when String doesn't match the expected format * @see java.text.SimpleDateFormat */ public static Date convertStringToDate(String aMask, String strDate) throws ParseException { SimpleDateFormat df; Date date; df = new SimpleDateFormat(aMask); if (log.isDebugEnabled()) { log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'"); } try { date = df.parse(strDate); } catch (ParseException pe) { //log.error("ParseException: " + pe); throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }