Package org.technologybrewery.baton.util
Class FileUtils
java.lang.Object
org.technologybrewery.baton.util.FileUtils
Common file-related logic used when performing a migration.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringInfers the indentation style from the given line.getRegExCaptureGroups(String regex, File file) Retrieves capture groups from a regular expression match inside a file.getRegExCaptureGroups(String regex, String input) Retrieves capture groups from a regular expression match inside a String.static booleanhasRegExMatch(String regex, File file) Evaluates a regex pattern against a file to determine if at least one regex match existsstatic voidindentValues(List<String> values, int numSpaces) Indent the values the desired number of tabs with a variable tab size.static booleanmodifyRegexMatchInFile(File file, String regex, String substring, String replacement) Evaluates a file against a regex pattern and replaces a substring of each regex match with a specified replacement.readAllFileLines(File file) static booleanreplaceInFile(File file, String regex, String replacement) Evaluates a file against a regex pattern and replaces the captured string(s) of each regex match with a specified replacementstatic booleanreplaceLiteralInFile(File file, String toReplace, String replacement) Evaluates a file against a literal string and replaces each match with a specified replacement.static void
-
Method Details
-
replaceLiteralInFile
public static boolean replaceLiteralInFile(File file, String toReplace, String replacement) throws IOException Evaluates a file against a literal string and replaces each match with a specified replacement.- Parameters:
file- the FiletoReplace- a string representing the text to replacereplacement- the replacement text to substitute the toReplace string- Returns:
- a boolean set to true if at least one replacement was performed in the file
- Throws:
IOException
-
replaceInFile
Evaluates a file against a regex pattern and replaces the captured string(s) of each regex match with a specified replacement- Parameters:
file- the Fileregex- a regex representing the text to replace, as a Stringreplacement- the replacement text to substitute the regex- Returns:
- a boolean set to true if at least one replacement was performed in the file
- Throws:
IOException
-
modifyRegexMatchInFile
public static boolean modifyRegexMatchInFile(File file, String regex, String substring, String replacement) Evaluates a file against a regex pattern and replaces a substring of each regex match with a specified replacement.- Parameters:
file- the Fileregex- a regex representing the text to replace a substring ofsubstring- the substring of the regex match that will be replacedreplacement- the replacement of the match substring- Returns:
- a boolean set to true if at least one modification was performed in the file
-
readAllFileLines
- Parameters:
file-Fileto read- Returns:
Listof the contents- Throws:
IOException
-
writeFile
- Parameters:
file-Fileto writecontents-Listof the contents- Throws:
IOException
-
getRegExCaptureGroups
Retrieves capture groups from a regular expression match inside a file.- Parameters:
regex- a regex containing capture groups, as a Stringfile- the file to search for matching capture groups- Returns:
- An ArrayList of Strings representing each capture group in the regex that was matched
- Throws:
IOException- See Also:
-
getRegExCaptureGroups
Retrieves capture groups from a regular expression match inside a String.- Parameters:
regex- a regex containing capture groups, as a Stringinput- the string to search for matching capture groups- Returns:
- An ArrayList of Strings representing each capture group in the regex that was matched
-
hasRegExMatch
Evaluates a regex pattern against a file to determine if at least one regex match exists- Parameters:
regex- a regex pattern, as a Stringfile- the file to search for matching substrings- Returns:
- true if there is at least one regex match, otherwise false
- Throws:
IOException
-
getIndent
Infers the indentation style from the given line.- Parameters:
line- the line to infer the indentation style fromlevel- the level of indentation of the line- Returns:
- a single indent in the inferred style
-
indentValues
Indent the values the desired number of tabs with a variable tab size.- Parameters:
values- List ofStringvalues to indentnumSpaces- number of spaces to indent
-