// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResourceKey.java
// public interface LepResourceKey {
// 
//     String getId();
// 
//     Version getVersion();
// 
// }
// 
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/Version.java
// public interface Version {
// 
//     /**
//      * Gets version identificator, for example:
//      * <br>
//      * 'b324', '1-alpha', '1.2.3', '1.0-RELEASE', '2.2-RC1', '2.2.3-M1', '12032017112331', etc.
//      *
//      * @return version id
//      */
//     String getId();
// 
// }


import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import com.icthh.xm.lep.api.LepResourceKey;
import com.icthh.xm.lep.api.Version;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
        try {
            URLStreamHandler keyHandler;
            if (handler == null && urlSpec.startsWith(LEP_PROTOCOL + ":")) {
                keyHandler = buildDefaultStreamHandler();
            } else {
                keyHandler = handler;
            }

            return new URL(null, urlSpec, keyHandler);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Can't build URL by LEP resource spec: "
                                                   + urlSpec
                                                   + " because of error: "
                                                   + e.getMessage(), e);
        }
    }

    private static URL buildUrl(String protocol,
                                String host,
                                int port,
                                String resourceKeyId,
                                URLStreamHandler handler) {
        try {
            return new URL(protocol, host, port, resourceKeyId, getUrlStreamHandler(protocol, handler));
        } catch (MalformedURLException e) {
            throw new IllegalStateException("Error while creating LEP key: " + e.getMessage(), e);
        }
    }

    private static URLStreamHandler getUrlStreamHandler(String protocol, URLStreamHandler handler) {
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/LepResourceKey.java
// public interface LepResourceKey {
// 
//     String getId();
// 
//     Version getVersion();
// 
// }
// 
// Path: xm-lep-api/src/main/java/com/icthh/xm/lep/api/Version.java
// public interface Version {
// 
//     /**
//      * Gets version identificator, for example:
//      * <br>
//      * 'b324', '1-alpha', '1.2.3', '1.0-RELEASE', '2.2-RC1', '2.2.3-M1', '12032017112331', etc.
//      *
//      * @return version id
//      */
//     String getId();
// 
// }


// Path: xm-lep-api-commons/src/main/java/com/icthh/xm/lep/api/commons/UrlLepResourceKey.java
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import com.icthh.xm.lep.api.LepResourceKey;
import com.icthh.xm.lep.api.Version;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

        try {
            URLStreamHandler keyHandler;
            if (handler == null && urlSpec.startsWith(LEP_PROTOCOL + ":")) {
                keyHandler = buildDefaultStreamHandler();
            } else {
                keyHandler = handler;
            }

            return new URL(null, urlSpec, keyHandler);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Can't build URL by LEP resource spec: "
                                                   + urlSpec
                                                   + " because of error: "
                                                   + e.getMessage(), e);
        }
    }

    private static URL buildUrl(String protocol,
                                String host,
                                int port,
                                String resourceKeyId,
                                URLStreamHandler handler) {
        try {
            return new URL(protocol, host, port, resourceKeyId, getUrlStreamHandler(protocol, handler));
        } catch (MalformedURLException e) {
            throw new IllegalStateException("Error while creating LEP key: " + e.getMessage(), e);
        }
    }

    private static URLStreamHandler getUrlStreamHandler(String protocol, URLStreamHandler handler) {
        return (handler == null && LEP_PROTOCOL.equals(protocol)) ? buildDefaultStreamHandler() : handler;