本文整理了Java中java.text.ParseException.<init>()
方法的一些代码示例,展示了ParseException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ParseException.<init>()
方法的具体详情如下:
包路径:java.text.ParseException
类名称:ParseException
方法名:<init>
[英]Constructs a new instance of this class with its stack trace, detail message and the location of the error filled in.
[中]构造这个类的一个新实例,并填入堆栈跟踪、详细信息和错误位置。
代码示例来源:origin: spring-projects/spring-framework
@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;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@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;
}
代码示例来源:origin: prestodb/presto
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;
代码示例来源:origin: org.springframework/spring-context
@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;
}
代码示例来源:origin: redisson/redisson
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;
代码示例来源:origin: looly/hutool
@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;
}
代码示例来源:origin: alibaba/canal
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);
}
}
代码示例来源:origin: apache/drill
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;
代码示例来源:origin: looly/hutool
@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;
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: camunda/camunda-bpm-platform
final void parseFoldingWhiteSpace() throws ParseException {
if (!skipFoldingWhiteSpace()) {
throw new ParseException("Invalid input: expected FWS",
pos.getIndex());
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
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;
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: camunda/camunda-bpm-platform
final void parseChar(char ch) throws ParseException {
if (!skipChar(ch)) {
throw new ParseException("Invalid input: expected '" + ch + "'",
pos.getIndex());
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
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;
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: camunda/camunda-bpm-platform
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());
}
}
代码示例来源:origin: prestodb/presto
@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());
}
代码示例来源:origin: jfoenixadmin/JFoenix
@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);
}
}
};
代码示例来源:origin: com.sun.mail/javax.mail
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());
}
}
内容来源于网络,如有侵权,请联系作者删除!