Class FileIOUtils
java.lang.Object
org.apache.jackrabbit.oak.commons.FileIOUtils
Simple File utils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Decorates the given comparator and applies the function before delegating to the decorated comparator. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Appends the contents of the list of files to the given file and deletes the files if the delete flag is enabled.static File
copy
(InputStream stream) Copies an input stream to a file.static void
copyInputStreamToFile
(InputStream source, File destination) Copy the input stream to the given file.static Comparator<String>
lineBreakAwareComparator
(Comparator<String> delegate) Composing iterator which unescapes for line breaks and delegates to the given comparator.static void
Merges a list of files after sorting with thelexComparator
.static void
Merges a list of files after sorting with the given comparator.readStringsAsSet
(InputStream stream, boolean unescape) Reads strings from the given stream into a set and optionally unescaping for line breaks.static void
Sorts the given file externally using thelexComparator
and removes duplicates.static void
sort
(File file, Comparator<String> comparator) Sorts the given file externally with the given comparator and removes duplicates.static void
writeAsLine
(BufferedWriter writer, String str, boolean escape) Writes a string as a new line into the given buffered writer and optionally escapes the line for line breaks.static int
writeStrings
(Iterator<String> iterator, File f, boolean escape) Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.static int
writeStrings
(Iterator<String> iterator, File f, boolean escape, @NotNull Function<String, String> transformer, @Nullable Logger logger, @Nullable String message) Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.static int
writeStrings
(Iterator<String> iterator, File f, boolean escape, @Nullable Logger logger, @Nullable String message) Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.
-
Field Details
-
lexComparator
-
-
Method Details
-
sort
Sorts the given file externally using thelexComparator
and removes duplicates.- Parameters:
file
- file whose contents needs to be sorted- Throws:
IOException
-
sort
Sorts the given file externally with the given comparator and removes duplicates.- Parameters:
file
- file whose contents needs to be sortedcomparator
- to compare- Throws:
IOException
-
merge
Merges a list of files after sorting with thelexComparator
.- Parameters:
files
- files to mergeoutput
- merge output file- Throws:
IOException
-
merge
public static void merge(List<File> files, File output, Comparator<String> comparator) throws IOException Merges a list of files after sorting with the given comparator.- Parameters:
files
- files to mergeoutput
- merge output file- Throws:
IOException
-
copy
Copies an input stream to a file.- Parameters:
stream
- steam to copy- Returns:
- Throws:
IOException
-
append
Appends the contents of the list of files to the given file and deletes the files if the delete flag is enabled. If there is a scope for lines in the files containing line break characters it should be ensured that the files are written withwriteAsLine(BufferedWriter, String, boolean)
with true to escape line break characters.- Parameters:
files
-appendTo
-- Throws:
IOException
-
writeAsLine
public static void writeAsLine(BufferedWriter writer, String str, boolean escape) throws IOException Writes a string as a new line into the given buffered writer and optionally escapes the line for line breaks.- Parameters:
writer
- to write the stringstr
- the string to writeescape
- whether to escape string for line breaks- Throws:
IOException
-
writeStrings
public static int writeStrings(Iterator<String> iterator, File f, boolean escape) throws IOException Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.- Parameters:
iterator
- the source of the stringsf
- file to write toescape
- whether to escape for line breaks- Returns:
- count
- Throws:
IOException
-
writeStrings
public static int writeStrings(Iterator<String> iterator, File f, boolean escape, @Nullable @Nullable Logger logger, @Nullable @Nullable String message) throws IOException Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.- Parameters:
iterator
- the source of the stringsf
- file to write toescape
- escape whether to escape for line breakslogger
- logger to log progressmessage
- message to log- Returns:
- Throws:
IOException
-
writeStrings
public static int writeStrings(Iterator<String> iterator, File f, boolean escape, @NotNull @NotNull Function<String, String> transformer, @Nullable @Nullable Logger logger, @Nullable @Nullable String message) throws IOExceptionWrites string from the given iterator to the given file and optionally escape the written strings for line breaks.- Parameters:
iterator
- the source of the stringsf
- file to write toescape
- escape whether to escape for line breakstransformer
- any transformation on the inputlogger
- logger to log progressmessage
- message to log- Returns:
- Throws:
IOException
-
readStringsAsSet
Reads strings from the given stream into a set and optionally unescaping for line breaks.- Parameters:
stream
- the source of the stringsunescape
- whether to unescape for line breaks- Returns:
- set
- Throws:
IOException
-
lineBreakAwareComparator
Composing iterator which unescapes for line breaks and delegates to the given comparator. When using this it should be ensured that the data source has been correspondingly escaped.- Parameters:
delegate
- the actual comparison iterator- Returns:
- comparator aware of line breaks
-
copyInputStreamToFile
Copy the input stream to the given file. Delete the file in case of exception.- Parameters:
source
- the input stream sourcedestination
- the file to write to- Throws:
IOException
-