@Test public void moveToDirExsistingOverwrite() throws TaskOutputVisitException, IOException { File existing = folder.newFile(); assertEquals(0, existing.length()); DefaultMultipleOutputWriter victim = new DefaultMultipleOutputWriter(ExistingOutputPolicy.OVERWRITE, context); Path outFile = Files.createTempFile("sejda", ".tmp"); Files.write(outFile, new byte[] { 0, 1, 1, 1 }); victim.addOutput(FileOutput.file(outFile.toFile()).name(existing.getName())); new DirectoryTaskOutput(existing.getParentFile()).accept(victim); assertEquals(1, existing.getParentFile().list().length); assertEquals(4, existing.getParentFile().listFiles()[0].length()); Files.deleteIfExists(outFile); }
@Override public void addOutput(PopulatedFileOutput fileOutput) { if (nonNull(multipleFiles.putIfAbsent(fileOutput.getName(), fileOutput.getFile()))) { int count = 1; String basename = getBaseName(fileOutput.getName()); String extension = getExtension(fileOutput.getName()); while (nonNull( multipleFiles.putIfAbsent(format("%s(%d).%s", basename, count, extension), fileOutput.getFile())) && count < 100) { count++; } } }
DefaultMultipleOutputWriter implements MultipleOutputWriter { @Override public void addOutput(PopulatedFileOutput fileOutput) { if (nonNull(multipleFiles.putIfAbsent(fileOutput.getName(), fileOutput.getFile()))) { int count = 1; String basename = getBaseName(fileOutput.getName()); String extension = getExtension(fileOutput.getName()); while (nonNull( multipleFiles.putIfAbsent(format("%s(%d).%s", basename, count, extension), fileOutput.getFile())) && count < 100) { count++; } } } }
DefaultMultipleOutputWriter implements MultipleOutputWriter { @Override public void addOutput(PopulatedFileOutput fileOutput) { if (nonNull(multipleFiles.putIfAbsent(fileOutput.getName(), fileOutput.getFile()))) { int count = 1; String basename = getBaseName(fileOutput.getName()); String extension = getExtension(fileOutput.getName()); while (nonNull( multipleFiles.putIfAbsent(format("%s(%d).%s", basename, count, extension), fileOutput.getFile())) && count < 100) { count++; } } } DefaultMultipleOutputWriter(ExistingOutputPolicy existingOutputPolicy, TaskExecutionContext executionContext); }
DefaultMultipleOutputWriter implements MultipleOutputWriter { @Override public void addOutput(PopulatedFileOutput fileOutput) { if (nonNull(multipleFiles.putIfAbsent(fileOutput.getName(), fileOutput.getFile()))) { int count = 1; String basename = getBaseName(fileOutput.getName()); String extension = getExtension(fileOutput.getName()); while (nonNull( multipleFiles.putIfAbsent(format("%s(%d).%s", basename, count, extension), fileOutput.getFile())) && count < 100) { count++; } } } DefaultMultipleOutputWriter(ExistingOutputPolicy existingOutputPolicy, TaskExecutionContext executionContext); @Override void dispatch(FileTaskOutput output); @Override void dispatch(DirectoryTaskOutput output); @Override void dispatch(FileOrDirectoryTaskOutput output); @Override void addOutput(PopulatedFileOutput fileOutput); }
DefaultMultipleOutputWriter implements MultipleOutputWriter { @Override public void addOutput(PopulatedFileOutput fileOutput) { if (nonNull(multipleFiles.putIfAbsent(fileOutput.getName(), fileOutput.getFile()))) { int count = 1; String basename = getBaseName(fileOutput.getName()); String extension = getExtension(fileOutput.getName()); while (nonNull( multipleFiles.putIfAbsent(format("%s(%d).%s", basename, count, extension), fileOutput.getFile())) && count < 100) { count++; } } } DefaultMultipleOutputWriter(ExistingOutputPolicy existingOutputPolicy, TaskExecutionContext executionContext); @Override void dispatch(FileTaskOutput output); @Override void dispatch(DirectoryTaskOutput output); @Override void dispatch(FileOrDirectoryTaskOutput output); @Override void addOutput(PopulatedFileOutput fileOutput);  }