Skip to content

Commit

Permalink
Increment count before starting new file in ObjectFileWriter
Browse files Browse the repository at this point in the history
To avoid overwriting first output file, e.g. when using batch-reset
  • Loading branch information
fsteeg committed Oct 5, 2023
1 parent 9cf783f commit b45391a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void process(final T obj) {
@Override
public void resetStream() {
closeStream();
startNewFile();
++count;
startNewFile();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.metafacture.io;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import java.io.File;
Expand Down Expand Up @@ -93,6 +94,17 @@ public void shouldAppendToExistingFile() throws IOException {
assertOutput(DATA + "\n" + DATA + "\n");
}

@Test
public void shouldIncrementCountOnResetBeforeStartingNewFile() throws IOException {
final String pathWithVar = tempFolder.getRoot() + "/test-${i}";
writer = new ObjectFileWriter<String>(pathWithVar);
writer.process(DATA);
assertTrue(new File(tempFolder.getRoot(), "test-0").exists());
writer.resetStream(); // increments count, starts new file
writer.process(DATA);
assertTrue(new File(tempFolder.getRoot(), "test-1").exists());
}

@Override
protected ConfigurableObjectWriter<String> getWriter() {
return writer;
Expand Down

0 comments on commit b45391a

Please sign in to comment.