src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43991 jdk/src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java@b2661845440c
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 16491
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.net.www.protocol.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.UnknownServiceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.jar.JarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.jar.Manifest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class JarURLConnection extends java.net.JarURLConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /* the Jar file factory. It handles both retrieval and caching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
16491
272ad530ce3a 8010282: sun.net.www.protocol.jar.JarFileFactory.close(JarFile) should be thread-safe
chegar
parents: 5506
diff changeset
    54
    private static final JarFileFactory factory = JarFileFactory.getInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /* the url for the Jar file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private URL jarFileURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* the permission to get this JAR file. This is the actual, ultimate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * permission, returned by the jar file factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Permission permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* the url connection for the JAR file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private URLConnection jarFileURLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /* the entry name, if any */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private String entryName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* the JarEntry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private JarEntry jarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* the jar file corresponding to this connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private JarFile jarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* the content type for this connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private String contentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public JarURLConnection(URL url, Handler handler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    throws MalformedURLException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        super(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        jarFileURL = getJarFileURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        jarFileURLConnection = jarFileURL.openConnection();
43991
b2661845440c 8175261: Per-protocol cache setting not working for JAR URLConnection
chegar
parents: 40938
diff changeset
    85
        // whether, or not, the embedded URL should use the cache will depend
b2661845440c 8175261: Per-protocol cache setting not working for JAR URLConnection
chegar
parents: 40938
diff changeset
    86
        // on this instance's cache value
b2661845440c 8175261: Per-protocol cache setting not working for JAR URLConnection
chegar
parents: 40938
diff changeset
    87
        jarFileURLConnection.setUseCaches(useCaches);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        entryName = getEntryName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public JarFile getJarFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return jarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public JarEntry getJarEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return jarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public Permission getPermission() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return jarFileURLConnection.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    class JarURLInputStream extends java.io.FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        JarURLInputStream (InputStream src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            super (src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public void close () throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (!getUseCaches()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    jarFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (!connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            /* the factory call will do the security checks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            jarFile = factory.get(getJarFileURL(), getUseCaches());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            /* we also ask the factory the permission that was required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
             * to get the jarFile, and set it as our permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (getUseCaches()) {
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents: 31061
diff changeset
   131
                boolean oldUseCaches = jarFileURLConnection.getUseCaches();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                jarFileURLConnection = factory.getConnection(jarFile);
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents: 31061
diff changeset
   133
                jarFileURLConnection.setUseCaches(oldUseCaches);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if ((entryName != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                jarEntry = (JarEntry)jarFile.getEntry(entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        if (!getUseCaches()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                            jarFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    throw new FileNotFoundException("JAR entry " + entryName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                                    " not found in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                                    jarFile.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        InputStream result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new IOException("no entry name specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                throw new FileNotFoundException("JAR entry " + entryName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                                " not found in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                jarFile.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            result = new JarURLInputStream (jarFile.getInputStream(jarEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int getContentLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        long result = getContentLengthLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (result > Integer.MAX_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return (int) result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public long getContentLengthLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        long result = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                /* if the URL referes to an archive */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                result = jarFileURLConnection.getContentLengthLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                /* if the URL referes to an archive entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                result = getJarEntry().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public Object getContent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        Object result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            result = jarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            result = super.getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String getContentType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                contentType = "x-java/jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    InputStream in = jarFile.getInputStream(jarEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    contentType = guessContentTypeFromStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                        new BufferedInputStream(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    // don't do anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                contentType = guessContentTypeFromName(entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                contentType = "content/unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return contentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public String getHeaderField(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return jarFileURLConnection.getHeaderField(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Sets the general request property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param   key     the keyword by which the request is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *                  (e.g., "<code>accept</code>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param   value   the value associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void setRequestProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        jarFileURLConnection.setRequestProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns the value of the named general request property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return  the value of the named general request property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *           connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public String getRequestProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return jarFileURLConnection.getRequestProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Adds a general request property specified by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * key-value pair.  This method will not overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * existing values associated with the same key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param   key     the keyword by which the request is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *                  (e.g., "<code>accept</code>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param   value   the value associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void addRequestProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        jarFileURLConnection.addRequestProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns an unmodifiable Map of general request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * properties for this connection. The Map keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * are Strings that represent the request-header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * field names. Each Map value is a unmodifiable List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * of Strings that represents the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return  a Map of the general request properties for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Map<String,List<String>> getRequestProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return jarFileURLConnection.getRequestProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Set the value of the <code>allowUserInteraction</code> field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * this <code>URLConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param   allowuserinteraction   the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see     java.net.URLConnection#allowUserInteraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void setAllowUserInteraction(boolean allowuserinteraction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        jarFileURLConnection.setAllowUserInteraction(allowuserinteraction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns the value of the <code>allowUserInteraction</code> field for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @return  the value of the <code>allowUserInteraction</code> field for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *          this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see     java.net.URLConnection#allowUserInteraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public boolean getAllowUserInteraction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return jarFileURLConnection.getAllowUserInteraction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * cache control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Sets the value of the <code>useCaches</code> field of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <code>URLConnection</code> to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Some protocols do caching of documents.  Occasionally, it is important
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * to be able to "tunnel through" and ignore the caches (e.g., the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * "reload" button in a browser).  If the UseCaches flag on a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * is true, the connection is allowed to use whatever caches it can.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *  If false, caches are to be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *  The default value comes from DefaultUseCaches, which defaults to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void setUseCaches(boolean usecaches) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        jarFileURLConnection.setUseCaches(usecaches);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the value of this <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <code>useCaches</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @return  the value of this <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *          <code>useCaches</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public boolean getUseCaches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return jarFileURLConnection.getUseCaches();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Sets the value of the <code>ifModifiedSince</code> field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * this <code>URLConnection</code> to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   346
     * @param   ifmodifiedsince   the new value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see     java.net.URLConnection#ifModifiedSince
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void setIfModifiedSince(long ifmodifiedsince) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        jarFileURLConnection.setIfModifiedSince(ifmodifiedsince);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Sets the default value of the <code>useCaches</code> field to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param   defaultusecaches   the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public void setDefaultUseCaches(boolean defaultusecaches) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Returns the default value of a <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * <code>useCaches</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Ths default is "sticky", being a part of the static state of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * URLConnections.  This flag applies to the next, and all following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * URLConnections that are created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @return  the default value of a <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          <code>useCaches</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public boolean getDefaultUseCaches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return jarFileURLConnection.getDefaultUseCaches();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}