Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.ivy.util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
/**
* Convenient class used only for uncapitalization Usually use commons lang but here we do not want
* to have such a dependency for only one feature
*/
public final class StringUtils {
private StringUtils() {
// Utility class
}
public static String uncapitalize(String string) {
if (string == null || string.length() == 0) {
return string;
}
if (string.length() == 1) {
return string.toLowerCase(Locale.US);
}
return string.substring(0, 1).toLowerCase(Locale.US) + string.substring(1);
}
/**
* Returns the error message associated with the given Throwable. The error message returned
* will try to be as precise as possible, handling cases where e.getMessage() is not meaningful,
* like {@link NullPointerException} for instance.
*
* @param t
* the throwable to get the error message from
* @return the error message of the given exception
*/
public static String getErrorMessage(Throwable t) {
if (t == null) {
return "";
}
if (t instanceof InvocationTargetException) {
InvocationTargetException ex = (InvocationTargetException) t;
t = ex.getTargetException();
}
String errMsg = t instanceof RuntimeException ? t.getMessage() : t.toString();
if (errMsg == null || errMsg.length() == 0 || "null".equals(errMsg)) {
errMsg = t.getClass().getName() + " at " + t.getStackTrace()[0].toString();
}
return errMsg;
}
/**
* Returns the exception stack trace as a String.
*
* @param e
* the exception to get the stack trace from.
* @return the exception stack trace
*/
public static String getStackTrace(Throwable e) {
if (e == null) {
return "";
}
StringWriter sw = new StringWriter();
PrintWriter printWriter = new PrintWriter(sw, true);
e.printStackTrace(printWriter);
return sw.getBuffer().toString();
}
/**
* Joins the given object array in one string, each separated by the given separator.
*
* Example:
*
*