public class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static File |
DEFAULT_PLUGINS_DIR
Default name of plugin directory.
|
static File |
DEFAULT_RESOURCES_DIR
Default name of resource directory.
|
Modifier and Type | Method and Description |
---|---|
static String |
camelCaseToEnum(String camelCase)
Converts camelCaseStringsWithACRONYMS to CAMEL_CASE_STRINGS_WITH_ACRONYMS
|
static double |
computeRegressionTrend(Collection<TimestampedRecord<Number>> data)
Computes a linear regression trend of the data set provided.
|
static void |
copyTemplateFromResource(String resource,
Path target,
Properties properties)
Takes a resource as a StringTemplate, renders the template using the provided properties and stores it to the given path.
|
static String |
determineDefaultLocation(String locationSuffix)
Determines the default location of resources based on the resourcesDir constant.
|
static String |
filterProperties(String text)
Replaces all ${<property.name>} placeholders in a string
by respective value of the property named <property.name> using
SystemPropertyGetter . |
static String |
filterProperties(String text,
Matcher matcher,
PropertyGetter pg)
Filters properties in the given string.
|
static String |
getDefaultEncoding()
Gets the default encoding.
|
static String |
getFirstNotNull(String... values)
Returns the first not-null string in the provided list.
|
static String |
getProperty(String name)
Returns a property value.
|
static String |
getProperty(String name,
String defaultValue)
Returns a property value.
|
static String |
getResource(String resource)
Obtains the needed resource with full-path.
|
static URL |
getResourceAsUrl(String resource)
Obtains the needed resource with full-path as URL.
|
static void |
initDebugAgent()
Initializes the debug agent when configured.
|
static void |
initTimeStamps()
Initializes system properties that carry time stamps.
|
static URL |
locationToUrl(String location,
String defaultLocationProperty,
String defaultLocation,
String defaultSuffix)
Converts location to URL.
|
static URL |
locationToUrlWithCheck(String location,
String defaultLocationProperty,
String defaultLocation,
String... defaultSuffix)
Converts location to URL with check for the location existence.
|
static void |
logProperties(org.apache.logging.log4j.Logger logger,
org.apache.logging.log4j.Level level,
Properties properties)
Writes the whole properties map to the given logger at the given level.
|
static void |
logProperties(org.apache.logging.log4j.Logger logger,
org.apache.logging.log4j.Level level,
Properties properties,
String prefix)
Writes the whole properties map to the given logger at the given level with the given prefix.
|
static String |
readFilteredContent(String fileLocation)
Reads the file location into a string while filtering properties.
|
static String |
readFilteredContent(URL url)
Reads URL (file) content into a string.
|
static List<String> |
readFilteredLines(String fileLocation)
Reads the lines from the given file location.
|
static List<String> |
readLines(String fileLocation)
Reads the lines from the given location.
|
static List<String> |
readLines(URL url)
Reads lines from the given URL as a list of strings.
|
static String |
readTemplateFromResource(String resource,
Properties properties)
Reads the given resource and processes it as a template.
|
static void |
setFirstNotNullProperty(Properties props,
String propName,
String... values)
Sets the property value to the first not-null value from the list.
|
static void |
setLoggingLevel(org.apache.logging.log4j.Level level)
Reconfigures the logging level of the root logger and all suitable appenders.
|
static String |
timeToHms(long time)
Converts time in milliseconds to H:MM:SS format, where H is unbound.
|
static void |
writeFileContent(File file,
String content)
Atomically writes given content to a file.
|
static void |
writeFileContent(Path path,
String content)
Atomically writes given content to a file.
|
static void |
writeFileContent(String fileName,
String content)
Atomically writes given content to a file.
|
public static final File DEFAULT_RESOURCES_DIR
public static final File DEFAULT_PLUGINS_DIR
public static String filterProperties(String text)
SystemPropertyGetter
.text
- The original string.public static String filterProperties(String text, Matcher matcher, PropertyGetter pg)
StringTemplate
instead.text
- The string to be filtered.matcher
- The matcher to find the properties, any user specified matcher can be provided.pg
- The PropertyGetter
to provide values of the properties.public static String getProperty(String name)
System.getProperty(String)
if the system property does not exist
it looks at environment variables using System.getenv(String)
. If
the variable does not exist the method returns a null
.name
- Property name.null
.public static String getProperty(String name, String defaultValue)
System.getProperty(String)
if the system property does not exist
it looks at environment variables using System.getenv(String)
. If
the variable does not exist the method returns defautValue
.name
- Property name.defaultValue
- Default property value.defaultValue
.public static void logProperties(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level, Properties properties)
logger
- The logger to log the properties.level
- The level at which to log the properties.properties
- The properties to log.public static void logProperties(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level, Properties properties, String prefix)
logger
- The logger to log the properties.level
- The level at which to log the properties.properties
- The properties to log.prefix
- The prefix to prepend to each log message (used for aligning with spaces, tabs, etc.).public static String readFilteredContent(URL url) throws IOException
url
- The file location as an URL.IOException
- When it was not possible to read the content.public static String readFilteredContent(String fileLocation) throws IOException
fileLocation
- The file location.IOException
- When it was not possible to read the content.public static List<String> readLines(URL url) throws IOException
url
- The URL to read the content from.IOException
- When it was not possible to read the content of the given URL.public static List<String> readLines(String fileLocation) throws IOException
readLines(URL)
.fileLocation
- The file name to read content from.IOException
- When it was not possible to read the content of the given file.public static List<String> readFilteredLines(String fileLocation) throws IOException
fileLocation
- The file name to read content from.IOException
- When it was not possible to read the content of the given file.public static URL locationToUrl(String location, String defaultLocationProperty, String defaultLocation, String defaultSuffix) throws MalformedURLException
location
- The location of the resource.defaultLocationProperty
- The property to read the default location prefix.defaultLocation
- The default value for defaultLocationProperty if this property is undefined.defaultSuffix
- The default suffix of the location.MalformedURLException
- When the location cannot be converted to a URL.public static URL locationToUrlWithCheck(String location, String defaultLocationProperty, String defaultLocation, String... defaultSuffix) throws MalformedURLException
location
- The location of the resource.defaultLocationProperty
- The property to read the default location prefix.defaultLocation
- The default value for defaultLocationProperty if this property is undefined.defaultSuffix
- The array of default default suffixes to try when searching for the resource.MalformedURLException
- When the location cannot be converted to an URL.public static String determineDefaultLocation(String locationSuffix)
locationSuffix
- The optional suffix to be added to the path.public static String camelCaseToEnum(String camelCase)
camelCase
- The camelCase string.public static String timeToHms(long time)
time
- The timestamp in milliseconds.public static String getDefaultEncoding()
PerfCakeConst.DEFAULT_ENCODING_PROPERTY
system property, if this property is not set, UTF-8 is used.public static double computeRegressionTrend(Collection<TimestampedRecord<Number>> data)
data
- Data on which to compute the trend.public static void setFirstNotNullProperty(Properties props, String propName, String... values)
props
- The properties instance.propName
- The name of the property to be set.values
- The list of possibilities, the first not-null is used to set the property value.public static String getFirstNotNull(String... values)
values
- The list of possible values.public static URL getResourceAsUrl(String resource) throws PerfCakeException
resource
- The name of the resource to obtain.PerfCakeException
- In the case of wrong resource name.public static String getResource(String resource) throws PerfCakeException
resource
- The name of the resource to obtain.PerfCakeException
- In the case of wrong resource name.public static void writeFileContent(String fileName, String content) throws PerfCakeException
fileName
- The target file name.content
- The content to be written.PerfCakeException
- In the case of s file operations failure.public static void writeFileContent(File file, String content) throws PerfCakeException
file
- The target file.content
- The content to be written.PerfCakeException
- In the case of file operations failure.public static void writeFileContent(Path path, String content) throws PerfCakeException
path
- The target file path.content
- The content to be written.PerfCakeException
- In the case of file operations failure.public static void copyTemplateFromResource(String resource, Path target, Properties properties) throws PerfCakeException
resource
- The resource location of a template.target
- The target path where to store the rendered template file.properties
- The properties to fill into the template.PerfCakeException
- When it is not possible to render the template or store the target file.public static String readTemplateFromResource(String resource, Properties properties) throws PerfCakeException
resource
- The resource location of a template.properties
- The properties to fill into the template.PerfCakeException
- When it was not possible to read the resource.public static void setLoggingLevel(org.apache.logging.log4j.Level level)
level
- The desired level.public static void initTimeStamps()
public static void initDebugAgent()
Copyright © 2010–2017 PerfCake Community. All rights reserved.