Object
Substitutor
Performs string substitution according to the given mapping.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionmaskSecrets
(String text, List<String> secrets) Finds all secrets in the input text and replaces them with a maskmaskSecretsFunc
(List<String> secrets) static boolean
restoreBackup
(Path file) substitute
(String text, Map<String, String> mapping) Substitutes all values and return new stringEquivalent tosubstitute(Path, Map)
except allows to substitute only files which satisfy given filter.substitute
(Path target, Map<String, String> mapping) Performs inplace substitution in a given file or in case of directory, in all files inside it.Equivalent tosubstitutePerLine(Path, Map)
except allows to substitute only files which satisfy given filter.substitutePerLine
(Path target, Map<String, String> mapping) Performs inplace line by line substitution in a given directory or file.Creates and returns a new list by iterating over the input list and performing line by line string substitution as defined in the mapping.Create backup of the original file when doing any changes.Allow to specify regexps in mapping
-
Constructor Details
-
Substitutor
public Substitutor()
-
-
Method Details
-
withRegexpSupport
Allow to specify regexps in mapping -
withBackup
Create backup of the original file when doing any changes. If no changes are done, backup file is not created. If backup file already exists then it is replaced. -
substitutePerLine
Creates and returns a new list by iterating over the input list and performing line by line string substitution as defined in the mapping. -
substitutePerLine
Performs inplace line by line substitution in a given directory or file.- Throws:
IOException
-
substitutePerLine
public List<Path> substitutePerLine(Path target, Predicate<Path> fileFilter, Map<String, String> mapping) throws IOExceptionEquivalent tosubstitutePerLine(Path, Map)
except allows to substitute only files which satisfy given filter.- Throws:
IOException
-
restoreBackup
- Throws:
IOException
-
substitute
Substitutes all values and return new string -
substitute
public List<Path> substitute(Path target, Predicate<Path> fileFilter, Map<String, String> mapping) throws IOExceptionEquivalent tosubstitute(Path, Map)
except allows to substitute only files which satisfy given filter.- Throws:
IOException
-
substitute
Performs inplace substitution in a given file or in case of directory, in all files inside it. It differs fromsubstitutePerLine(Path, Map)
that it reads entire file in memory as a single string and performs substitution on such string. This allows to create multiline mappings and perform multiline substitutions (of course this requires appropriate Java pattern which should support multiline matching, this can be done by prepending "(?s)(?m)" to it).- Throws:
IOException
-
maskSecrets
Finds all secrets in the input text and replaces them with a mask -
maskSecretsFunc
- Returns:
- function which accepts input text and masks all secrets in it
-