Class FileIOUtils

java.lang.Object
org.apache.jackrabbit.oak.commons.FileIOUtils

public final class FileIOUtils extends Object
Simple File utils
  • Field Details

  • Method Details

    • sort

      public static void sort(File file) throws IOException
      Sorts the given file externally using the lexComparator and removes duplicates.
      Parameters:
      file - file whose contents needs to be sorted
      Throws:
      IOException
    • sort

      public static void sort(File file, Comparator<String> comparator) throws IOException
      Sorts the given file externally with the given comparator and removes duplicates.
      Parameters:
      file - file whose contents needs to be sorted
      comparator - to compare
      Throws:
      IOException
    • merge

      public static void merge(List<File> files, File output) throws IOException
      Merges a list of files after sorting with the lexComparator.
      Parameters:
      files - files to merge
      output - 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 merge
      output - merge output file
      Throws:
      IOException
    • copy

      public static File copy(InputStream stream) throws IOException
      Copies an input stream to a file.
      Parameters:
      stream - steam to copy
      Returns:
      Throws:
      IOException
    • append

      public static void append(List<File> files, File appendTo, boolean delete) throws 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 with writeAsLine(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 string
      str - the string to write
      escape - 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 strings
      f - file to write to
      escape - 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 strings
      f - file to write to
      escape - escape whether to escape for line breaks
      logger - logger to log progress
      message - 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 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 strings
      f - file to write to
      escape - escape whether to escape for line breaks
      transformer - any transformation on the input
      logger - logger to log progress
      message - message to log
      Returns:
      Throws:
      IOException
    • readStringsAsSet

      public static Set<String> readStringsAsSet(InputStream stream, boolean unescape) throws IOException
      Reads strings from the given stream into a set and optionally unescaping for line breaks.
      Parameters:
      stream - the source of the strings
      unescape - whether to unescape for line breaks
      Returns:
      set
      Throws:
      IOException
    • lineBreakAwareComparator

      public static Comparator<String> lineBreakAwareComparator(Comparator<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(InputStream source, File destination) throws IOException
      Copy the input stream to the given file. Delete the file in case of exception.
      Parameters:
      source - the input stream source
      destination - the file to write to
      Throws:
      IOException