/*
 * @(#)TestURIEncoding.java
 *
 * Summary: Encode a URI using RFC 2396.
 *
 * Copyright: (c) 2009 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.6+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * Version History:
 *  1.1 2009-01-28
 */
package com.mindprod.example;

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

import static java.lang.System.out;

/**
 * Encode a URI using RFC 2396.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.1 2009-01-28
 * @since 2009
 */
public final class TestURIEncoding
    {
    // --------------------------- 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 );

        out.println( uri.toString() );
        // prints http://www.example.com/you%20&%20I%2010%25?%20weird%20&%20weirder%20neé
        // note how  fails to encode é

        out.println( uri.toASCIIString() );
        // prints http://www.example.com/you%20&%20I%2010%25?%20weird%20&%20weirder%20ne%C3%A9
        // note how encodes é

        out.println( uri.toURL().toString() );
        // prints http://www.example.com/you%20&%20I%2010%25?%20wierd%20&%20wierder%20neé
        // note how  fails to encode é
        }
    }