List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.cometd.common.Jackson2JSONContext.java
public T[] parse(InputStream stream) throws ParseException { try {/*from www .j av a 2s. co m*/ return getObjectMapper().readValue(stream, rootArrayType); } catch (IOException x) { throw (ParseException) new ParseException("", -1).initCause(x); } }
From source file:ubic.basecode.util.DateUtil.java
/** * This method generates a string representation of a date/time in the format you specify on input * /*from w w w. ja v a 2s . 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 * @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); try { date = df.parse(strDate); } catch (ParseException pe) { throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }
From source file:com.branded.holdings.qpc.web.EmotionTypeFormatter.java
@Override public EmotionType parse(String text, Locale locale) throws ParseException { Collection<EmotionType> findEmotionTypes = this.topicService.findEmotionTypes(); for (EmotionType type : findEmotionTypes) { if (type.getName().equals(text)) { return type; }// w ww. j a va 2 s . co m } throw new ParseException("type not found: " + text, 0); }
From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java
public static Date parse(String value) throws ParseException { if (StringUtils.isEmpty(value)) { //prevent null pointer and index out of bounds exceptions. throw new ParseException("Date is not provided", 0); }//w ww .ja v a2 s. c o m //ref: http://www.java2s.com/Code/Java/Data-Type/ISO8601dateparsingutility.htm //assume date is like: '2015-11-11T20:32:37Z' String modValue = value.substring(0, value.length() - 1) + "GMT-00:00"; SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); return parser.parse(modValue); }
From source file:org.osaf.cosmo.model.text.XhtmlPreferenceFormat.java
public Preference parse(String source, EntityFactory entityFactory) throws ParseException { Preference pref = entityFactory.createPreference(); try {// ww w . j ava 2 s. c o m if (source == null) throw new ParseException("Source has no XML data", -1); StringReader sr = new StringReader(source); XMLStreamReader reader = createXmlReader(sr); boolean inPreference = false; while (reader.hasNext()) { reader.next(); if (!reader.isStartElement()) continue; if (hasClass(reader, "preference")) { if (log.isDebugEnabled()) log.debug("found preference element"); inPreference = true; continue; } if (inPreference && hasClass(reader, "key")) { if (log.isDebugEnabled()) log.debug("found key element"); String key = reader.getElementText(); if (StringUtils.isBlank(key)) handleParseException("Key element must not be empty", reader); pref.setKey(key); continue; } if (inPreference && hasClass(reader, "value")) { if (log.isDebugEnabled()) log.debug("found value element"); String value = reader.getElementText(); if (StringUtils.isBlank(value)) value = ""; pref.setValue(value); continue; } } reader.close(); } catch (XMLStreamException e) { handleXmlException("Error reading XML", e); } return pref; }
From source file:org.apache.hadoop.chukwa.rest.bean.ConfigBean.java
public ConfigBean(JSONObject json) throws ParseException { try {//from w w w . j a v a2 s .co m key = json.getString("key"); value = json.getString("value"); } catch (Exception e) { log.error(ExceptionUtil.getStackTrace(e)); throw new ParseException("Error parsing user object.", 0); } }
From source file:com.indoqa.lang.util.DateRangeParser.java
public static long getOffsetInMilliseconds(String relativeString) throws ParseException { if (StringUtils.isBlank(relativeString)) { throw new ParseException("Relative date string is emtpy or null!", 0); }/*from w ww . j av a 2 s. c o m*/ long result = 0; String[] parts = relativeString.split(" "); int pos = 0; for (String part : parts) { String unit = extractUnit(relativeString, pos, part); int partOffset = extractPartOffset(relativeString, pos, part, unit); result += partOffset * UNIT_CONVERSIONS.get(unit); pos += part.length() + 1; } return result; }
From source file:com.blackberry.logdriver.timestamp.Rfc3164TimestampParser.java
@Override public long parseTimestatmp(String timestamp) throws ParseException { if (timestamp == null) { throw new ParseException("Timestamp is null", 0); }/* w ww .j av a2 s. c om*/ // Before we parse the date, add the current year to the string. That way, // we get a correct timestamp. If I try to add the year after, we run into // issues with leap years. Calendar currentCalendar = Calendar.getInstance(); int currentYear = currentCalendar.get(Calendar.YEAR); Date date = dateFormat.parse(currentYear + " " + timestamp); Calendar logCalendar = Calendar.getInstance(); logCalendar.setTime(date); // If today is the first of January, and the log is for the 31st of // December, then we probably just used the wrong year. So lets roll the // year back by one in that case. if (logCalendar.get(Calendar.DAY_OF_MONTH) == 31 && logCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && currentCalendar.get(Calendar.DAY_OF_MONTH) == 1 && currentCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, -1); // Contrariwise, a bad clock can give us Jan 1 logs on December 31 } else if (currentCalendar.get(Calendar.DAY_OF_MONTH) == 31 && currentCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && logCalendar.get(Calendar.DAY_OF_MONTH) == 1 && logCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, 1); } return logCalendar.getTimeInMillis(); }
From source file:ubic.gemma.util.DateUtil.java
/** * This method generates a string representation of a date/time in the format you specify on input * /* www.ja v a2 s . com*/ * @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) { throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }
From source file:org.kalypso.wspwin.core.LocalEnergyLossBean.java
/** * Reads a psi file (Energieverluste/Verlustbeiwerte/local energy losses) *///from ww w . java 2 s. c o m public static LocalEnergyLossBean[] read(final File lelFile) throws ParseException, IOException { final List<LocalEnergyLossBean> beans = new ArrayList<>(0); LineIterator lineIt = null; try { if (lelFile.exists()) { int count = 0; for (lineIt = FileUtils.lineIterator(lelFile, null); lineIt.hasNext();) { final String nextLine = lineIt.nextLine(); count++; final StringTokenizer tokenizer = new StringTokenizer(nextLine); if (tokenizer.countTokens() % 2 != 0) throw new ParseException( Messages.getString("org.kalypso.wspwin.core.LocalEnergyLossBean.1") + nextLine, //$NON-NLS-1$ count); final int countKinds = tokenizer.countTokens() / 2 - 1; final String key = tokenizer.nextToken(); if (!STATION.equalsIgnoreCase(key)) throw new ParseException(Messages.getString("org.kalypso.wspwin.core.LocalEnergyLossBean.2") //$NON-NLS-1$ + STATION + "': " + nextLine, count); //$NON-NLS-1$ final BigDecimal station = new BigDecimal(tokenizer.nextToken()); // read pairs: kind -> value final Collection<Pair<String, BigDecimal>> entries = new ArrayList<>(); for (int i = 0; i < countKinds; i++) { final String kind = tokenizer.nextToken(); final BigDecimal value = new BigDecimal(tokenizer.nextToken()); entries.add(Pair.of(kind, value)); } final LocalEnergyLossBean lossBean = new LocalEnergyLossBean(station, entries.toArray(new Pair[entries.size()])); beans.add(lossBean); } } return beans.toArray(new LocalEnergyLossBean[beans.size()]); } finally { LineIterator.closeQuietly(lineIt); } }