package org.eclipse.dawnsci.nexus.builder.impl;

import org.eclipse.dawnsci.nexus.INexusFileFactory;
import org.eclipse.dawnsci.nexus.NexusException;
import org.eclipse.dawnsci.nexus.NexusFile;
import org.eclipse.dawnsci.nexus.ServiceHolder;
import org.eclipse.dawnsci.nexus.builder.NexusScanFile;

class DefaultNexusScanFile implements NexusScanFile {

	private final String filePath;
	
	private NexusFile nexusFile = null;
	
	protected DefaultNexusScanFile(final String filePath) {
		this.filePath = filePath;
	}
	
	@Override
	public void openToWrite() throws NexusException {
		if (nexusFile != null) {
			throw new IllegalStateException("NexusFile is already open.");
		}
		final INexusFileFactory nexusFileFactory = ServiceHolder.getNexusFileFactory();
		nexusFile = nexusFileFactory.newNexusFile(filePath, true);
		nexusFile.openToWrite(false); // file must already exist on disk
		nexusFile.activateSwmrMode();
	}

	@Override
	public void flush() throws NexusException {
		if (nexusFile == null) {
			throw new IllegalStateException("NexusFile has not been opened.");
		}
		
		nexusFile.flush();
	}

	@Override
	public void close() throws NexusException {
		if (nexusFile == null) {
			throw new IllegalStateException("NexusFile has not been opened.");
		}
		nexusFile.flush();
		nexusFile.close();
		nexusFile = null;
	}

}

@@ -881,16 +881,31 @@
  disk%0A%09%09
+%0A%09%09try %7B%0A%09%09    
 nexusFil
@@ -922,24 +922,266 @@
 SwmrMode();%0A
+%09%09%7D catch (NexusException nxsE) %7B%0A%09%09%09System.out.println(%22Scan to '%22+nexusFile.getFilePath()+%22' is not SWMR %22+nxsE.getMessage());%0A%09%09%09// We are not in SWMR mode so we allow a non-SWMR write, which works but other processes may have issues.%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Overri
@@ -1257,86 +1257,81 @@
 ll) 
-%7B%0A%09%09%09throw new IllegalStateException(%22NexusFile has not been opened.%22);%0A%09%09%7D%0A%09%09
+return;  // Legal flush can be called on non-SWMR files and does nothing.
 %0A%09%09n
@@ -1437,83 +1437,69 @@
 ll) 
-%7B%0A%09%09%09throw new IllegalStateException(%22NexusFi
+return; // Legal this is an AutoClosab
 le 
+t
 ha
-s not been opened.%22);%0A%09%09%7D
+t does if it can.
 %0A%09%09n

Make DefaultNexusScanFile work in non-SWMR mode again. non-SWMR mode is allowed for scanning.