Class FileIOUtils
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.FileIOUtils
-
public final class FileIOUtils extends java.lang.Object
Simple File utils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileIOUtils.BurnOnCloseFileIterator<T>
Deprecated.useBurnOnCloseFileIterator
insteadstatic class
FileIOUtils.FileLineDifferenceIterator
Deprecated.useFileLineDifferenceIterator
insteadstatic class
FileIOUtils.TransformingComparator
Decorates the given comparator and applies the function before delegating to the decorated comparator.
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<java.lang.String>
lexComparator
static Function<java.lang.String,java.lang.String>
passThruTransformer
Deprecated.useFunction.identity()
instead
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
append(java.util.List<java.io.File> files, java.io.File appendTo, boolean delete)
Appends the contents of the list of files to the given file and deletes the files if the delete flag is enabled.static java.io.File
copy(java.io.InputStream stream)
Copies an input stream to a file.static void
copyInputStreamToFile(java.io.InputStream source, java.io.File destination)
Copy the input stream to the given file.static java.util.Comparator<java.lang.String>
lineBreakAwareComparator(java.util.Comparator<java.lang.String> delegate)
Composing iterator which unescapes for line breaks and delegates to the given comparator.static void
merge(java.util.List<java.io.File> files, java.io.File output)
Merges a list of files after sorting with thelexComparator
.static void
merge(java.util.List<java.io.File> files, java.io.File output, java.util.Comparator<java.lang.String> comparator)
Merges a list of files after sorting with the given comparator.static java.util.Set<java.lang.String>
readStringsAsSet(java.io.InputStream stream, boolean unescape)
Reads strings from the given stream into a set and optionally unescaping for line breaks.static void
sort(java.io.File file)
Sorts the given file externally using thelexComparator
and removes duplicates.static void
sort(java.io.File file, java.util.Comparator<java.lang.String> comparator)
Sorts the given file externally with the given comparator and removes duplicates.static void
writeAsLine(java.io.BufferedWriter writer, java.lang.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(java.util.Iterator<java.lang.String> iterator, java.io.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(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, @NotNull Function<java.lang.String,java.lang.String> transformer, @Nullable Logger logger, @Nullable java.lang.String message)
Deprecated.static int
writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, @Nullable Logger logger, @Nullable java.lang.String message)
Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.static int
writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, java.util.function.Function<java.lang.String,java.lang.String> transformer, @Nullable Logger logger, @Nullable java.lang.String message)
Writes string from the given iterator to the given file and optionally escape the written strings for line breaks.
-
-
-
Field Detail
-
lexComparator
public static final java.util.Comparator<java.lang.String> lexComparator
-
passThruTransformer
@Deprecated public static final Function<java.lang.String,java.lang.String> passThruTransformer
Deprecated.useFunction.identity()
instead
-
-
Method Detail
-
sort
public static void sort(java.io.File file) throws java.io.IOException
Sorts the given file externally using thelexComparator
and removes duplicates.- Parameters:
file
- file whose contents needs to be sorted- Throws:
java.io.IOException
-
sort
public static void sort(java.io.File file, java.util.Comparator<java.lang.String> comparator) throws java.io.IOException
Sorts the given file externally with the given comparator and removes duplicates.- Parameters:
file
- file whose contents needs to be sortedcomparator
- to compare- Throws:
java.io.IOException
-
merge
public static void merge(java.util.List<java.io.File> files, java.io.File output) throws java.io.IOException
Merges a list of files after sorting with thelexComparator
.- Parameters:
files
- files to mergeoutput
- merge output file- Throws:
java.io.IOException
-
merge
public static void merge(java.util.List<java.io.File> files, java.io.File output, java.util.Comparator<java.lang.String> comparator) throws java.io.IOException
Merges a list of files after sorting with the given comparator.- Parameters:
files
- files to mergeoutput
- merge output file- Throws:
java.io.IOException
-
copy
public static java.io.File copy(java.io.InputStream stream) throws java.io.IOException
Copies an input stream to a file.- Parameters:
stream
- steam to copy- Returns:
- Throws:
java.io.IOException
-
append
public static void append(java.util.List<java.io.File> files, java.io.File appendTo, boolean delete) throws java.io.IOException
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:
java.io.IOException
-
writeAsLine
public static void writeAsLine(java.io.BufferedWriter writer, java.lang.String str, boolean escape) throws java.io.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:
java.io.IOException
-
writeStrings
public static int writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape) throws java.io.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:
java.io.IOException
-
writeStrings
public static int writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, @Nullable @Nullable Logger logger, @Nullable @Nullable java.lang.String message) throws java.io.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:
java.io.IOException
-
writeStrings
public static int writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, @NotNull java.util.function.Function<java.lang.String,java.lang.String> transformer, @Nullable @Nullable Logger logger, @Nullable @Nullable java.lang.String message) throws java.io.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 breakstransformer
- any transformation on the inputlogger
- logger to log progressmessage
- message to log- Returns:
- Throws:
java.io.IOException
-
writeStrings
@Deprecated public static int writeStrings(java.util.Iterator<java.lang.String> iterator, java.io.File f, boolean escape, @NotNull @NotNull Function<java.lang.String,java.lang.String> transformer, @Nullable @Nullable Logger logger, @Nullable @Nullable java.lang.String message) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
readStringsAsSet
public static java.util.Set<java.lang.String> readStringsAsSet(java.io.InputStream stream, boolean unescape) throws java.io.IOException
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:
java.io.IOException
-
lineBreakAwareComparator
public static java.util.Comparator<java.lang.String> lineBreakAwareComparator(java.util.Comparator<java.lang.String> delegate)
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
public static void copyInputStreamToFile(java.io.InputStream source, java.io.File destination) throws java.io.IOException
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:
java.io.IOException
-
-