alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (UrlUtilTest2.java)

This example Struts source code file (UrlUtilTest2.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

inputstream, io, ioexception, ioexception, jar, jarinputstream, jarinputstream, net, network, testcase, url, url, urlutiltest2, urlutiltest2

The Struts UrlUtilTest2.java source code

package com.opensymphony.xwork2.util;

import junit.framework.TestCase;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarInputStream;

/**
 * Keep these test on a separate class, they can't be in UrlUtilTest because the
 * registered URLStreamHandlerFactory would make them fail
 */
public class UrlUtilTest2 extends TestCase {
    public void testOpenWithJarProtocol() throws IOException {
        URL url = ClassLoaderUtil.getResource("xwork-jar.jar", URLUtil.class);
        URL jarUrl = new URL("jar", "", url.toExternalForm() + "!/");
        URL outputURL = URLUtil.normalizeToFileProtocol(jarUrl);
        assertNotNull(outputURL);
        assertUrlCanBeOpened(outputURL);
    }

    private void assertUrlCanBeOpened(URL url) throws IOException {
        InputStream is = url.openStream();
        JarInputStream jarStream = null;
        try {
            jarStream = new JarInputStream(is);
            assertNotNull(jarStream);
        } finally {
            if (jarStream != null)
                jarStream.close();

        }
    }
}

Other Struts examples (source code examples)

Here is a short list of links related to this Struts UrlUtilTest2.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.