test/jdk/sun/net/www/protocol/jar/JarURLConnectionUseCaches.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     1
/*
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     4
 *
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     8
 *
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    13
 * accompanied this code).
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    14
 *
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    18
 *
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    21
 * questions.
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    22
 */
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    23
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    24
/*
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    25
 * @test
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    26
 * @bug 6947916
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    27
 * @summary  JarURLConnection does not handle useCaches correctly
40976
744b4a436a4b 8165988: Test JarURLConnectionUseCaches.java fails at windows: failed to clean up files after test
robm
parents: 40938
diff changeset
    28
 * @run main/othervm JarURLConnectionUseCaches
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    29
 */
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    30
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    31
import java.io.*;
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    32
import java.net.JarURLConnection;
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    33
import java.net.URL;
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    34
import java.util.jar.*;
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    35
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    36
public class JarURLConnectionUseCaches {
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    37
    public static void main( String[] args ) throws IOException {
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    38
        JarOutputStream out = new JarOutputStream(
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    39
                new FileOutputStream("usecache.jar"));
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    40
        out.putNextEntry(new JarEntry("test.txt"));
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    41
        out.write("Test txt file".getBytes());
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    42
        out.closeEntry();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    43
        out.close();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    44
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    45
        URL url = new URL("jar:"
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    46
            + new File(".").toURI().toString()
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    47
            + "/usecache.jar!/test.txt");
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    48
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    49
        JarURLConnection c1 = (JarURLConnection)url.openConnection();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    50
        c1.setDefaultUseCaches( false );
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    51
        c1.setUseCaches( true );
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    52
        c1.connect();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    53
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    54
        JarURLConnection c2 = (JarURLConnection)url.openConnection();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    55
        c2.setDefaultUseCaches( false );
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    56
        c2.setUseCaches( true );
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    57
        c2.connect();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    58
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    59
        c1.getInputStream().close();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    60
        c2.getInputStream().read();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    61
        c2.getInputStream().close();
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    62
    }
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents:
diff changeset
    63
}