package com.mindprod.example;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * Encode a URL using RFC 2396.
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0, 2006-03-02
 */
public final class TestURLEncode
    {
// --------------------------- main() method ---------------------------

    /**
     * Test URL encode via URI to URL.
     *
     * @param args not used
     * @throws MalformedURLException if test URL illegal.
     * @throws URISyntaxException    if URL mangled.
     */
    public static void main( String[] args ) throws URISyntaxException, MalformedURLException
        {
        // reserved chars that are not escaped in URLs include:
        // ; / ? : @ & = + $ ,
        URI uri = new URI( "http", "//www.example.com/you & I 10%? weird & weirder neé", null );
        System.out.println( uri.toURL().toString() );
        // prints http://www.example.com/you%20&%20I%2010%25?%20wierd%20&%20wierder%20neé
        // note how item fails to encode é
        }
    }