Skip to content

File Modification And Merging

Asterios Raptis edited this page Feb 10, 2025 · 10 revisions

Overview

This packages provides utilities for modifying and merging files and directories.

Package Structure

  • io.github.astrapi69.file.modify.api

    • FileChangeable - Interface for modifying files.
  • io.github.astrapi69.file.modify

    • ModifyFileExtensions - Utility class for modifying files.
    • DeleteLinesByIndexInFile - Deletes specific lines from a file.
  • io.github.astrapi69.file.merge.strategy

    • MergeStrategy - Enum defining directory merge strategies.
  • io.github.astrapi69.file.merge

    • MergeDirectoryExtensions - Provides methods for merging directories.

Interfaces and Classes

FileChangeable (Interface)

Defines a function for modifying files line by line.

Methods:

  • apply(Integer lineIndex, String line) - Modifies a line based on its index.

ModifyFileExtensions

Utility class for modifying files.

Methods:

  • concatenateAll(List<File> textFiles, File resultTextFile) - Concatenates multiple files into one.
  • modifyFile(Path inFilePath, Charset charsetOfOutputFile, FileChangeable modifier) - Modifies a file line by line.
  • modifyFile(Path inFilePath, FileChangeable modifier) - Modifies a file using UTF-8 encoding.
  • modifyFile(Path inFilePath, Path outFilePath, Charset charsetOfOutputFile, FileChangeable modifier) - Modifies a file and writes to a new output file.
  • modifyFile(Path inFilePath, Path outFilePath, FileChangeable modifier) - Modifies a file and writes to a new output file using UTF-8.

DeleteLinesByIndexInFile

Deletes specific lines from a file based on line indexes.

Properties:

  • lineIndexesToDelete - List of indexes to be deleted.

Methods:

  • apply(Integer lineIndex, String line) - Returns null for lines that should be deleted.

MergeStrategy

Defines strategies for merging directories.

Strategies:

  • TARGET_AS_MASTER - Copies from source to target and removes from source if necessary.
  • SOURCE_TO_TARGET - Copies from source to target without removing files.

MergeDirectoryExtensions

Provides methods for merging directories.

Methods:

  • merge(File targetDir, File... directoriesToMerge) - Merges directories into a target directory.

Clone this wiki locally