This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/io/github/spair/jtgmerge/command/SeparatorOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.github.spair.jtgmerge.command; | ||
|
||
import io.github.spair.jtgmerge.util.Separator; | ||
import picocli.CommandLine.Option; | ||
|
||
final class SeparatorOption { | ||
|
||
@Option(names = {"--separator"}, description = "Separator to split lines. Accepts: ${COMPLETION-CANDIDATES}") | ||
Separator separator = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.spair.jtgmerge.util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
public final class FileUtil { | ||
|
||
public static void convertLineEndings(final File file, final Separator separator) { | ||
if (separator == null) { | ||
return; | ||
} | ||
|
||
try { | ||
String fileContent = new String(Files.readAllBytes(file.toPath())); | ||
fileContent = fileContent.replace(System.lineSeparator(), separator.separator()); | ||
Files.write(file.toPath(), fileContent.getBytes(), StandardOpenOption.TRUNCATE_EXISTING); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
private FileUtil() { | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/spair/jtgmerge/util/Separator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.spair.jtgmerge.util; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public enum Separator { | ||
|
||
WIN("\r\n"), | ||
NIX("\n"); | ||
|
||
private final String separatorChars; | ||
|
||
public String separator() { | ||
return separatorChars; | ||
} | ||
} |