@Test public void addFilesRenamesExisting() throws TaskOutputVisitException, IOException { DefaultMultipleOutputWriter victim = new DefaultMultipleOutputWriter(ExistingOutputPolicy.FAIL, context); victim.addOutput(FileOutput.file(folder.newFile()).name("myName.pdf")); victim.addOutput(FileOutput.file(folder.newFile()).name("myName.pdf")); victim.addOutput(FileOutput.file(folder.newFile()).name("myName.pdf")); File outFolder = folder.newFolder(); new DirectoryTaskOutput(outFolder).accept(victim); assertEquals(3, outFolder.list().length); }
@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);  }