Package ch.grengine.source
Class SourceUtil
java.lang.Object
ch.grengine.source.SourceUtil
Static utility methods around
Source.- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
Method Summary
Modifier and TypeMethodDescriptionfilesToSourceSet(SourceFactory sourceFactory, File... files) creates a source set from the given script files, using the given source factory.filesToSourceSet(SourceFactory sourceFactory, Collection<File> files) creates a source set from the given collections of script files, using the given source factory.filesToSourceSet(File... files) creates a source set from the given script files, using the default source factory.filesToSourceSet(Collection<File> files) creates a source set from the given collections of script files, using the default source factory.static StringgetTextStartNoLineBreaks(String text, int maxLen) gets the start of the given text with line breaks removed.static Stringcalculates a cryptographic hash function (message digest).static Stringcalculates an MD5 hash.static StringreadUrlText(URL url, String encoding) reads the content from the given URL using the given character encoding.sourceArrayToSourceSet(Source... sourceArray) converts the given source varargs or array of source to a set of source.sourceCollectionToSourceSet(Collection<Source> sourceCollection) converts the given collection of source to a set of source.sourceToSourceSet(Source source) converts the given source to a set of source that contains only the given source.textsToSourceSet(SourceFactory sourceFactory, String... texts) creates a source set from the given script texts, using the given source factory.textsToSourceSet(SourceFactory sourceFactory, Collection<String> texts) creates a source set from the given collections of script texts, using the given source factory.textsToSourceSet(SourceFactory sourceFactory, Map<String, String> texts) creates a source set from the given map of desired class name to script text, using the given source factory.textsToSourceSet(String... texts) creates a source set from the given script texts, using the default source factory.textsToSourceSet(Collection<String> texts) creates a source set from the given collections of script texts, using the default source factory.textsToSourceSet(Map<String, String> texts) creates a source set from the given map of desired class name to script text, using the default source factory.static Fileconverts the given file to the canonical file, with fallback to the absolute file if getting the canonical file failed.urlsToSourceSet(SourceFactory sourceFactory, URL... urls) creates a source set from the given script URLs, using the given source factory.urlsToSourceSet(SourceFactory sourceFactory, Collection<URL> urls) creates a source set from the given collections of script URLs, using the given source factory.urlsToSourceSet(URL... urls) creates a source set from the given script URLs, using the default source factory.urlsToSourceSet(Collection<URL> urls) creates a source set from the given collections of script URLs, using the default source factory.
-
Method Details
-
textsToSourceSet
creates a source set from the given collections of script texts, using the default source factory.- Parameters:
texts- script texts- Returns:
- source set
- Since:
- 1.0
-
textsToSourceSet
creates a source set from the given script texts, using the default source factory.- Parameters:
texts- script texts- Returns:
- source set
- Since:
- 1.0
-
textsToSourceSet
creates a source set from the given collections of script texts, using the given source factory.- Parameters:
sourceFactory- source factorytexts- script texts- Returns:
- source set
- Since:
- 1.0
-
textsToSourceSet
creates a source set from the given script texts, using the given source factory.- Parameters:
sourceFactory- source factorytexts- script texts- Returns:
- source set
- Since:
- 1.0
-
textsToSourceSet
creates a source set from the given map of desired class name to script text, using the default source factory.- Parameters:
texts- map of desired class name to script text- Returns:
- source set
- Since:
- 1.0
-
textsToSourceSet
creates a source set from the given map of desired class name to script text, using the given source factory.- Parameters:
sourceFactory- source factorytexts- map of desired class name to script text- Returns:
- source set
- Since:
- 1.0
-
filesToSourceSet
creates a source set from the given collections of script files, using the default source factory.- Parameters:
files- script files- Returns:
- source set
- Since:
- 1.0
-
filesToSourceSet
creates a source set from the given script files, using the default source factory.- Parameters:
files- script files- Returns:
- source set
- Since:
- 1.0
-
filesToSourceSet
creates a source set from the given collections of script files, using the given source factory.- Parameters:
sourceFactory- source factoryfiles- script files- Returns:
- source set
- Since:
- 1.0
-
filesToSourceSet
creates a source set from the given script files, using the given source factory.- Parameters:
sourceFactory- source factoryfiles- script files- Returns:
- source set
- Since:
- 1.0
-
urlsToSourceSet
creates a source set from the given collections of script URLs, using the default source factory.- Parameters:
urls- script URLs- Returns:
- source set
- Since:
- 1.0
-
urlsToSourceSet
creates a source set from the given script URLs, using the default source factory.- Parameters:
urls- script URLs- Returns:
- source set
- Since:
- 1.0
-
urlsToSourceSet
creates a source set from the given collections of script URLs, using the given source factory.- Parameters:
sourceFactory- source factoryurls- script URLs- Returns:
- source set
- Since:
- 1.0
-
urlsToSourceSet
creates a source set from the given script URLs, using the given source factory.- Parameters:
sourceFactory- source factoryurls- script URLs- Returns:
- source set
- Since:
- 1.0
-
sourceToSourceSet
converts the given source to a set of source that contains only the given source.- Parameters:
source- source- Returns:
- source set
- Since:
- 1.0
-
sourceCollectionToSourceSet
converts the given collection of source to a set of source.- Parameters:
sourceCollection- source collection- Returns:
- source set
- Since:
- 1.0
-
sourceArrayToSourceSet
converts the given source varargs or array of source to a set of source.- Parameters:
sourceArray- source varargs or array of source- Returns:
- source set
- Since:
- 1.0
-
hash
calculates a cryptographic hash function (message digest).The given text is first UTF-8 encoded to bytes, then the given hash is calculated and finally returned as a hex string.
- Parameters:
text- the text to hashalgorithm- the hash algorithm to use- Returns:
- hash hex string
- Throws:
UnsupportedOperationException- if the given hash algorithm is not available- Since:
- 1.0
-
md5
calculates an MD5 hash.The given text is first UTF-8 encoded to bytes, then the MD5 hash is calculated and finally returned as a hex string.
- Parameters:
text- the text to hash- Returns:
- MD5 hash text string
- Throws:
UnsupportedOperationException- if MD5 is not available (which is very unlikely)- Since:
- 1.0
-
getTextStartNoLineBreaks
gets the start of the given text with line breaks removed.The returned text is at most maxLen characters long and line breaks are converted to "%n". If the text had to be cut, this is indicated by "[..]" at the end of the returned text.
- Parameters:
text- textmaxLen- maximal length of the returned text- Returns:
- start of the given text with line breaks removed
- Throws:
IllegalArgumentException- if maxLen is less than 10- Since:
- 1.1.1
-
readUrlText
reads the content from the given URL using the given character encoding.- Parameters:
url- URLencoding- encoding, e.g. "UTF-8"- Returns:
- URL content text
- Throws:
IOException- if could not read from the URL- Since:
- 1.0
-
toCanonicalOrAbsoluteFile
converts the given file to the canonical file, with fallback to the absolute file if getting the canonical file failed.The returned file is thus guaranteed to be an absolute file.
- Parameters:
file- file- Returns:
- canonical or absolute file
- Since:
- 1.0
-