package org.metaborg.util.file;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;

import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;

import com.google.common.collect.Lists;

public class FileUtils {
    public static File toFile(FileObject fileObject) {
        final URI uri = toURI(fileObject);
        final File file = new File(uri);
        return file;
    }

    public static Iterable<File> toFiles(Iterable<FileObject> fileObjects) {
        final Collection<File> files = Lists.newLinkedList();
        for(FileObject fileObject : fileObjects) {
            files.add(toFile(fileObject));
        }
        return files;
    }

    public static URI toURI(FileObject fileObject) {
        try {
            final FileName name = fileObject.getName();
            final String uriString = URIEncode.encode(name.getURI());
            return new URI(uriString);
        } catch(URISyntaxException e) {
            throw new RuntimeException("Could not convert FileObject to URI", e);
        }
    }
}

@@ -132,16 +132,48 @@
 lection;
+%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -317,16 +317,98 @@
 Utils %7B%0A
+    private static Pattern sanitizePattern = Pattern.compile(%22%5B%5Ea-zA-Z0-9.-%5D%22);%0A%0A%0A
     publ
@@ -1207,11 +1207,129 @@
  %7D%0A    %7D
+%0A%0A    public static String sanitize(String path) %7B%0A        return sanitizePattern.matcher(path).replaceAll(%22_%22);%0A    %7D
 %0A%7D%0A

Add path sanitization utility.