Skip to content

Commit

Permalink
[update][plugin][txtfilewriter] Improve handling of file suffixes
Browse files Browse the repository at this point in the history
1. Use it if `fileName` item contains suffix, or
2. Add correspond suffix name via `fileFormat` item, `txt` is the default
3. Add correspond compress suffix if `compress` present
  • Loading branch information
wgzhao committed Oct 21, 2024
1 parent f825a49 commit 2ad2a5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,18 @@ public static List<Configuration> split(Configuration writerSliceConfig, Set<Str
Set<String> allFileExists = new HashSet<>(originAllFileExists);

String filePrefix = writerSliceConfig.getString(Key.FILE_NAME);

String suffix="";
if (filePrefix.contains(".")) {
String[] split = filePrefix.split("\\.");
filePrefix = split[0];
suffix = "." + split[1];
}
for (int i = 0; i < mandatoryNumber; i++) {
// handle same file name
Configuration splitTaskConfig = writerSliceConfig.clone();
String fullFileName;
do {
fullFileName = String.format("%s__%s", filePrefix, FileHelper.generateFileMiddleName());
fullFileName = String.format("%s_%s%s", filePrefix, FileHelper.generateFileMiddleName(), suffix);
}
while (allFileExists.contains(fullFileName));
allFileExists.add(fullFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -228,9 +227,10 @@ public void init()
public void prepare()
{
String compress = this.writerSliceConfig.getString(COMPRESS);
if (!fileName.contains(".")) {
this.fileName = this.fileName + "." + this.fileFormat;
}
suffix = FileHelper.getCompressFileSuffix(compress);

this.fileName = this.fileName + "." + this.fileFormat;
}

@Override
Expand Down

0 comments on commit 2ad2a5b

Please sign in to comment.