Refine search
@Override public Number parse(String text, Locale locale) throws ParseException { NumberFormat format = getNumberFormat(locale); ParsePosition position = new ParsePosition(0); Number number = format.parse(text, position); if (position.getErrorIndex() != -1) { throw new ParseException(text, position.getIndex()); } if (!this.lenient) { if (text.length() != position.getIndex()) { // indicates a part of the string that was not parsed throw new ParseException(text, position.getIndex()); } } return number; }
@Override public Date parse(final String source) throws ParseException { final ParsePosition pp = new ParsePosition(0); final Date date= parse(source, pp); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException( "(The " +locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \""+source, pp.getErrorIndex()); } throw new ParseException("Unparseable date: "+source, pp.getErrorIndex()); } return date; }
Exception fail = null; try { int offset = pos.getIndex(); msg = "("+fail.getClass().getName()+")"; ParseException ex = new ParseException("Failed to parse date " + input + ": " + msg, pos.getIndex()); ex.initCause(fail); throw ex;
@Override public Number parse(String text, Locale locale) throws ParseException { NumberFormat format = getNumberFormat(locale); ParsePosition position = new ParsePosition(0); Number number = format.parse(text, position); if (position.getErrorIndex() != -1) { throw new ParseException(text, position.getIndex()); } if (!this.lenient) { if (text.length() != position.getIndex()) { // indicates a part of the string that was not parsed throw new ParseException(text, position.getIndex()); } } return number; }
Exception fail = null; try { int offset = pos.getIndex(); msg = "("+fail.getClass().getName()+")"; ParseException ex = new ParseException("Failed to parse date " + input + ": " + msg, pos.getIndex()); ex.initCause(fail); throw ex;
@Override public Date parse(final String source) throws ParseException { final ParsePosition pp = new ParsePosition(0); final Date date = parse(source, pp); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException("(The " + locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \"" + source, pp.getErrorIndex()); } throw new ParseException("Unparseable date: " + source, pp.getErrorIndex()); } return date; }
private Date parseDate(String str, String[] parsePatterns, Locale locale) throws ParseException { if ((str == null) || (parsePatterns == null)) { throw new IllegalArgumentException("Date and Patterns must not be null"); } SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { parser = new SimpleDateFormat(parsePatterns[0], locale); } else { parser.applyPattern(parsePatterns[i]); } pos.setIndex(0); Date date = parser.parse(str, pos); if ((date != null) && (pos.getIndex() == str.length())) { return date; } } throw new ParseException("Unable to parse the date: " + str, -1); } }
Exception fail = null; try { int offset = pos.getIndex(); msg = "("+fail.getClass().getName()+")"; ParseException ex = new ParseException("Failed to parse date " + input + ": " + msg, pos.getIndex()); ex.initCause(fail); throw ex;
@Override public Date parse(final String source) throws ParseException { final ParsePosition pp = new ParsePosition(0); final Date date = parse(source, pp); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException("(The " + locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \"" + source, pp.getErrorIndex()); } throw new ParseException("Unparseable date: " + source, pp.getErrorIndex()); } return date; }
/** * Parses a {@code Number} from the specified string using the rules of this * number format. * * @param string * the string to parse. * @return the {@code Number} resulting from the parsing. * @throws ParseException * if an error occurs during parsing. */ public Number parse(String string) throws ParseException { ParsePosition pos = new ParsePosition(0); Number number = parse(string, pos); if (pos.getIndex() == 0) { throw new ParseException("Unparseable number: \"" + string + "\"", pos.getErrorIndex()); } return number; }
final void parseFoldingWhiteSpace() throws ParseException { if (!skipFoldingWhiteSpace()) { throw new ParseException("Invalid input: expected FWS", pos.getIndex()); } }
public Date parse(final String source) throws ParseException { final Date date = parse(source, new ParsePosition(0)); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException( "(The " + locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \"" + source + "\" does not match " + parsePattern.pattern(), 0); } throw new ParseException("Unparseable date: \"" + source + "\" does not match " + parsePattern.pattern(), 0); } return date; }
/** * Parses a date from the specified string using the rules of this date * format. * * @param string * the string to parse. * @return the {@code Date} resulting from the parsing. * @throws ParseException * if an error occurs during parsing. */ public Date parse(String string) throws ParseException { ParsePosition position = new ParsePosition(0); Date date = parse(string, position); if (position.getIndex() == 0) { throw new ParseException("Unparseable date: \"" + string + "\"", position.getErrorIndex()); } return date; }
final void parseChar(char ch) throws ParseException { if (!skipChar(ch)) { throw new ParseException("Invalid input: expected '" + ch + "'", pos.getIndex()); } }
public Date parse(final String source) throws ParseException { final Date date = parse(source, new ParsePosition(0)); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException( "(The " + locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \"" + source + "\" does not match " + parsePattern.pattern(), 0); } throw new ParseException("Unparseable date: \"" + source + "\" does not match " + parsePattern.pattern(), 0); } return date; }
/** * Parses the specified string using the rules of this format. * * @param string * the string to parse. * @return the object resulting from the parse. * @throws ParseException * if an error occurs during parsing. */ public Object parseObject(String string) throws ParseException { ParsePosition position = new ParsePosition(0); Object result = parseObject(string, position); if (position.getIndex() == 0) { throw new ParseException("Parse failure", position.getErrorIndex()); } return result; }
int parseYear() throws ParseException { int year = parseAsciiDigits(4, MAX_YEAR_DIGITS); if (year >= 1900) { return year; } else { pos.setIndex(pos.getIndex() - 4); while (text.charAt(pos.getIndex() - 1) == '0') { pos.setIndex(pos.getIndex() - 1); } throw new ParseException("Invalid year", pos.getIndex()); } }
@Override public Date parse(String dateStr) throws ParseException { dateStr = dateStr.trim(); ParsePosition pos = new ParsePosition(0); Date dt = _parseDate(dateStr, pos); if (dt != null) { return dt; } StringBuilder sb = new StringBuilder(); for (String f : ALL_FORMATS) { if (sb.length() > 0) { sb.append("\", \""); } else { sb.append('"'); } sb.append(f); } sb.append('"'); throw new ParseException (String.format("Cannot parse date \"%s\": not compatible with any of standard forms (%s)", dateStr, sb.toString()), pos.getErrorIndex()); }
@Override public Number fromString(String string) { try { if (string == null) { return null; } string = string.trim(); if (string.length() < 1) { return null; } // Create and configure the parser to be used NumberFormat parser = getNumberFormat(); ParsePosition parsePosition = new ParsePosition(0); Number result = parser.parse(string, parsePosition); final int index = parsePosition.getIndex(); if (index == 0 || index < string.length()) { throw new ParseException("Unparseable number: \"" + string + "\"", parsePosition.getErrorIndex()); } return result; } catch (ParseException ex) { throw new RuntimeException(ex); } } };
int parseYear() throws ParseException { int year = parseAsciiDigits(4, MAX_YEAR_DIGITS); if (year >= 1900) { return year; } else { pos.setIndex(pos.getIndex() - 4); while (text.charAt(pos.getIndex() - 1) == '0') { pos.setIndex(pos.getIndex() - 1); } throw new ParseException("Invalid year", pos.getIndex()); } }