package org.opencb.opencga.core.common;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;

/**
 * Created by hpccoll1 on 11/05/15.
 */
public class UriUtils {

    public static void checkUri(URI uri, String uriName, String schema) throws IOException {
        if(uri == null || uri.getScheme() != null && !uri.getScheme().equals(schema)) {
            throw new IOException("Expected file:// uri scheme for " + uriName);
        }
    }

    public static URI createUri(String input) throws URISyntaxException {
        URI sourceUri = new URI(null, input, null);
        if (sourceUri.getScheme() == null || sourceUri.getScheme().isEmpty()) {
            sourceUri = Paths.get(input).toUri();
        }
        return sourceUri;
    }

    public static URI createDirectoryUri(String input) throws URISyntaxException {
        if(!input.endsWith("/")) {
            input += "/";
        }
        return createUri(input);
    }

}

@@ -890,59 +890,321 @@
     
-if(!input.endsWith(%22/%22)) %7B%0A            input
+URI uri = createUri(input);%0A        // If path does not ends with / , create a new URI with path + %22/%22%0A        if(!uri.getPath().endsWith(%22/%22)) %7B%0A            uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),%0A                    uri.getPath()
  +
-=
  %22/%22
+, uri.getQuery(), uri.getFragment())
 ;%0A  
@@ -1226,32 +1226,19 @@
  return 
-createUri(input)
+uri
 ;%0A    %7D%0A

Fix UriUtils createDirectoryUri