Java Code Examples for java.net.JarURLConnection#connect()

The following examples show how to use java.net.JarURLConnection#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JarURLConnectionUseCaches.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 2
Source File: JarURLConnectionUseCaches.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 3
Source File: JarURLConnectionUseCaches.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 4
Source File: JarURLConnectionUseCaches.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 5
Source File: JarURLConnectionUseCaches.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 6
Source File: JarURLConnectionUseCaches.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 7
Source File: JarURLConnectionUseCaches.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args ) throws IOException {
    JarOutputStream out = new JarOutputStream(
            new FileOutputStream("usecache.jar"));
    out.putNextEntry(new JarEntry("test.txt"));
    out.write("Test txt file".getBytes());
    out.closeEntry();
    out.close();

    URL url = new URL("jar:"
        + new File(".").toURI().toString()
        + "/usecache.jar!/test.txt");

    JarURLConnection c1 = (JarURLConnection)url.openConnection();
    c1.setDefaultUseCaches( false );
    c1.setUseCaches( true );
    c1.connect();

    JarURLConnection c2 = (JarURLConnection)url.openConnection();
    c2.setDefaultUseCaches( false );
    c2.setUseCaches( true );
    c2.connect();

    c1.getInputStream().close();
    c2.getInputStream().read();
    c2.getInputStream().close();
}
 
Example 8
Source File: JarHolder.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
public void init()
{
    try
    {
        log.debug("JarHolder: attempting to connect to {}", urlpath);

        URL url = new URL( urlpath );
        conn = (JarURLConnection) url.openConnection();
        conn.setAllowUserInteraction(false);
        conn.setDoInput(true);
        conn.setDoOutput(false);
        conn.connect();
        theJar = conn.getJarFile();
    }
    catch (IOException ioe)
    {
        String msg = "JarHolder: error establishing connection to JAR at \""
                     + urlpath + "\"";
        log.error(msg, ioe);
        throw new VelocityException(msg, ioe);
    }
}
 
Example 9
Source File: JarURLResource.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public JarFile getJarFile() throws IOException {
    URL jarFileUrl = new URL("jar:" + jarUrl + "!/");
    JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
    conn.setUseCaches(false);
    conn.connect();
    return conn.getJarFile();
}
 
Example 10
Source File: JarURLResource.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public JarFile getJarFile() throws IOException {
    URL jarFileUrl = new URL("jar:" + jarUrl + "!/");
    JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
    conn.setUseCaches(false);
    conn.connect();
    return conn.getJarFile();
}
 
Example 11
Source File: ParserController.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private JarFile getJarFile(URL jarFileUrl) throws IOException {
JarFile jarFile = null;

if (jarFileUrl != null) {
    JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
    conn.setUseCaches(false);
    conn.connect();
    jarFile = conn.getJarFile();
}

return jarFile;
   }