package de.retest.recheck.review.workers;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Stream;

import de.retest.recheck.ignore.CacheFilter;
import de.retest.recheck.ignore.Filter;
import de.retest.recheck.ignore.JSFilterImpl;
import de.retest.recheck.ignore.RecheckIgnoreLocator;
import de.retest.recheck.review.GlobalIgnoreApplier;
import de.retest.recheck.review.GlobalIgnoreApplier.PersistableGlobalIgnoreApplier;
import de.retest.recheck.review.ignore.io.Loaders;

public class SaveFilterWorker {

	private final GlobalIgnoreApplier applier;
	private final RecheckIgnoreLocator locator;

	public SaveFilterWorker( final GlobalIgnoreApplier applier ) {
		this( applier, new RecheckIgnoreLocator() );
	}

	protected SaveFilterWorker( final GlobalIgnoreApplier applier, final RecheckIgnoreLocator locator ) {
		this.applier = applier;
		this.locator = locator;
	}

	public void save() throws IOException {
		final Optional<Path> ignorePath = locator.getProjectIgnoreFile();
		final PersistableGlobalIgnoreApplier persist = applier.persist();

		final File ignoreFile = ignorePath.orElse( locator.getUserIgnoreFile() ).toFile();
		if ( !ignoreFile.exists() ) {
			ignoreFile.getParentFile().mkdirs();
		}

		// Filter JSFilter because that would create unnecessary file content.
		final Stream<Filter> filters = persist.getIgnores().stream() //
				.map( this::extractCachedFilter ) //
				.filter( filter -> !(filter instanceof JSFilterImpl) );
		final Stream<String> save = Loaders.filter().save( filters );

		try ( final PrintStream writer = new PrintStream( new FileOutputStream( ignoreFile ) ) ) {
			save.forEach( writer::println );
		}
	}

	private Filter extractCachedFilter( final Filter filter ) {
		return filter instanceof CacheFilter ? ((CacheFilter) filter).getBase() : filter;
	}
}

@@ -61,41 +61,8 @@
 le;%0A
-import java.io.FileOutputStream;%0A
 impo
@@ -200,16 +200,57 @@
 tream;%0A%0A
+import org.apache.commons.io.FileUtils;%0A%0A
 import d
@@ -1194,170 +1194,8 @@
 );%0A%0A
-%09%09final File ignoreFile = ignorePath.orElse( locator.getUserIgnoreFile() ).toFile();%0A%09%09if ( !ignoreFile.exists() ) %7B%0A%09%09%09ignoreFile.getParentFile().mkdirs();%0A%09%09%7D%0A%0A
 %09%09//
@@ -1495,16 +1495,101 @@
 ers );%0A%0A
+%09%09final File ignoreFile = ignorePath.orElse( locator.getUserIgnoreFile() ).toFile();%0A
 %09%09try ( 
@@ -1636,16 +1636,22 @@
 am( 
-new 
 File
+Utils.open
 Outp

Use Apache commons openOutputStream