hu.blackbelt.epsilon.runtime.execution.impl.NioFilesystemnRelativePathURIHandlerImpl Maven / Gradle / Ivy
package hu.blackbelt.epsilon.runtime.execution.impl;
import lombok.Builder;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.URIHandlerImpl;
import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.PosixFileAttributeView;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Slf4j
@Builder
@ToString
public class NioFilesystemnRelativePathURIHandlerImpl extends URIHandlerImpl {
@Builder.Default
String urlSchema = "";
@Builder.Default
FileSystem fileSystem = FileSystems.getDefault();
@Builder.Default
String rootPath = "";
public NioFilesystemnRelativePathURIHandlerImpl(String urlSchema, FileSystem fileSystem, String rootPath) {
super();
this.fileSystem = fileSystem;
this.rootPath = rootPath;
this.urlSchema = urlSchema;
// log.info("Creating NIO filesystem URI handler on {}", rootPath);
}
@Override
public boolean canHandle(URI uri) {
if (urlSchema == null || urlSchema.equals("")) {
return true;
} else if (uri == null) {
return false;
} else if (uri.scheme() == null || uri.scheme().equals("")) {
return false;
} else {
return uri.scheme().equals(urlSchema);
}
}
/**
* Creates an output stream for the file path and returns it.
*
* This implementation allocates a {@link OutputStream} and creates subdirectories as necessary.
*
* @return an open output stream.
* @exception IOException if there is a problem obtaining an open output stream.
*/
@Override
public OutputStream createOutputStream(URI uri, Map, ?> options) throws IOException {
String parent = new File(getFullPath(uri)).getParent();
if (parent != null) {
Files.createDirectories(fileSystem.getPath(parent));
}
final Map