下面列出了org.apache.commons.lang3.ClassUtils#getShortClassName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
*/
public static String toStringWithRootCause(@Nullable Throwable t) {
if (t == null) {
return StringUtils.EMPTY;
}
final String clsName = ClassUtils.getShortClassName(t, null);
final String message = StringUtils.defaultString(t.getMessage());
Throwable cause = getRootCause(t);
StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
if (cause != t) {
sb.append("; <---").append(toStringWithShortName(cause));
}
return sb.toString();
}
/**
* 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
*/
public static String toStringWithRootCause(@Nullable Throwable t) {
if (t == null) {
return StringUtils.EMPTY;
}
final String clsName = ClassUtils.getShortClassName(t, null);
final String message = StringUtils.defaultString(t.getMessage());
Throwable cause = getRootCause(t);
StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
if (cause != t) {
sb.append("; <---").append(toStringWithShortName(cause));
}
return sb.toString();
}
public static String getMessage(Throwable e) {
String msg = getRootCauseMessage(e);
if (StringUtils.isBlank(msg)) {
msg = ClassUtils.getShortClassName(e.getClass());
}
return msg;
}
@Override
public final void activate(OperatorContext ctx)
{
isActive = true;
if (this instanceof Runnable) {
ioThread = new Thread((Runnable)this, "io-" + ClassUtils.getShortClassName(this.getClass()));
ioThread.start();
}
}
public static Object getValue(String fieldName, Object obj) {
Objects.requireNonNull(obj, "Class must not be null");
Objects.requireNonNull(fieldName, "Name must not be null");
Field field = findField(obj.getClass(), fieldName);
if (null == field) {
throw new ReflectionException(
"No Such field " + fieldName + " from class" + ClassUtils.getShortClassName(obj.getClass()));
}
try {
field.setAccessible(true);
return field.get(obj);
} catch (Exception e) {
throw new ReflectionException(fieldName, obj.getClass(), e);
}
}
public ReflectionException(String name, Class<?> clazz, Exception e) {
this("Error Reflect " + name + "from class " + ClassUtils.getShortClassName(clazz), e);
}
/**
* Gets a short message summarising the exception.
* <p>
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(final Throwable th) {
if (th == null) {
return "";
}
final String clsName = ClassUtils.getShortClassName(th, null);
final String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
/**
* Gets a short message summarising the exception.
* <p>
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(Throwable th) {
if (th == null) {
return "";
}
String clsName = ClassUtils.getShortClassName(th, null);
String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
/**
* Gets a short message summarising the exception.
* <p>
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(Throwable th) {
if (th == null) {
return "";
}
String clsName = ClassUtils.getShortClassName(th, null);
String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
/**
* Gets a short message summarising the exception.
* <p>
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(Throwable th) {
if (th == null) {
return "";
}
String clsName = ClassUtils.getShortClassName(th, null);
String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
/**
* Gets a short message summarising the exception.
* <p>
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(Throwable th) {
if (th == null) {
return "";
}
String clsName = ClassUtils.getShortClassName(th, null);
String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
/**
* 返回短Class名, 不包含PackageName.
*
* 内部类的话,返回"主类.内部类"
*/
public static String getShortClassName(final Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* 返回Class名,不包含PackageName
*
* 内部类的话,返回"主类.内部类"
*/
public static String getShortClassName(final String className) {
return ClassUtils.getShortClassName(className);
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(final Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* 返回Class名, 不包含PackageName.
*
* 内部类的话,返回"主类.内部类"
*/
public static String getShortClassName(final Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* 返回Class名,不包含PackageName
*
* 内部类的话,返回"主类.内部类"
*/
public static String getShortClassName(final String className) {
return ClassUtils.getShortClassName(className);
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(Class<?> cls) {
return ClassUtils.getShortClassName(cls);
}