jdk/src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java
author robm
Tue, 13 Sep 2016 14:47:29 +0100
changeset 40938 5b0977acc842
parent 31061 fead7d86d75f
child 43991 b2661845440c
permissions -rw-r--r--
6947916: JarURLConnection does not handle useCaches correctly Reviewed-by: chegar
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();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        entryName = getEntryName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public JarFile getJarFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return jarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public JarEntry getJarEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return jarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public Permission getPermission() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return jarFileURLConnection.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    class JarURLInputStream extends java.io.FilterInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        JarURLInputStream (InputStream src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            super (src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public void close () throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                if (!getUseCaches()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    jarFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
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
    public void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (!connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            /* the factory call will do the security checks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            jarFile = factory.get(getJarFileURL(), getUseCaches());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            /* we also ask the factory the permission that was required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
             * to get the jarFile, and set it as our permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (getUseCaches()) {
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents: 31061
diff changeset
   128
                boolean oldUseCaches = jarFileURLConnection.getUseCaches();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                jarFileURLConnection = factory.getConnection(jarFile);
40938
5b0977acc842 6947916: JarURLConnection does not handle useCaches correctly
robm
parents: 31061
diff changeset
   130
                jarFileURLConnection.setUseCaches(oldUseCaches);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if ((entryName != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                jarEntry = (JarEntry)jarFile.getEntry(entryName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        if (!getUseCaches()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            jarFile.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    throw new FileNotFoundException("JAR entry " + entryName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                                    " not found in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                                    jarFile.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        InputStream result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw new IOException("no entry name specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                throw new FileNotFoundException("JAR entry " + entryName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                                " not found in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                                jarFile.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            result = new JarURLInputStream (jarFile.getInputStream(jarEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public int getContentLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        long result = getContentLengthLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (result > Integer.MAX_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return (int) result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public long getContentLengthLong() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        long result = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (jarEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                /* if the URL referes to an archive */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                result = jarFileURLConnection.getContentLengthLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                /* if the URL referes to an archive entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                result = getJarEntry().getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public Object getContent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Object result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            result = jarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            result = super.getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public String getContentType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (entryName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                contentType = "x-java/jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    InputStream in = jarFile.getInputStream(jarEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    contentType = guessContentTypeFromStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                        new BufferedInputStream(in));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    // don't do anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                contentType = guessContentTypeFromName(entryName);
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 = "content/unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return contentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public String getHeaderField(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return jarFileURLConnection.getHeaderField(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Sets the general request property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param   key     the keyword by which the request is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *                  (e.g., "<code>accept</code>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param   value   the value associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void setRequestProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        jarFileURLConnection.setRequestProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns the value of the named general request property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return  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
    public String getRequestProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return jarFileURLConnection.getRequestProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Adds a general request property specified by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * key-value pair.  This method will not overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * existing values associated with the same key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param   key     the keyword by which the request is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *                  (e.g., "<code>accept</code>").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param   value   the value associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public void addRequestProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        jarFileURLConnection.addRequestProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns an unmodifiable Map of general request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * properties for this connection. The Map keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * are Strings that represent the request-header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * field names. Each Map value is a unmodifiable List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * of Strings that represents the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * field values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return  a Map of the general request properties for this connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public Map<String,List<String>> getRequestProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return jarFileURLConnection.getRequestProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Set the value of the <code>allowUserInteraction</code> field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * this <code>URLConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param   allowuserinteraction   the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see     java.net.URLConnection#allowUserInteraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void setAllowUserInteraction(boolean allowuserinteraction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        jarFileURLConnection.setAllowUserInteraction(allowuserinteraction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Returns the value of the <code>allowUserInteraction</code> field for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return  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
     * @see     java.net.URLConnection#allowUserInteraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public boolean getAllowUserInteraction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return jarFileURLConnection.getAllowUserInteraction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * cache control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Sets the value of the <code>useCaches</code> field of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <code>URLConnection</code> to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Some protocols do caching of documents.  Occasionally, it is important
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * to be able to "tunnel through" and ignore the caches (e.g., the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * "reload" button in a browser).  If the UseCaches flag on a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * is true, the connection is allowed to use whatever caches it can.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *  If false, caches are to be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *  The default value comes from DefaultUseCaches, which defaults to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public void setUseCaches(boolean usecaches) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        jarFileURLConnection.setUseCaches(usecaches);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns the value of this <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <code>useCaches</code> field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return  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
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public boolean getUseCaches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return jarFileURLConnection.getUseCaches();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Sets the value of the <code>ifModifiedSince</code> field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * this <code>URLConnection</code> to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
   343
     * @param   ifmodifiedsince   the new value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see     java.net.URLConnection#ifModifiedSince
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public void setIfModifiedSince(long ifmodifiedsince) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        jarFileURLConnection.setIfModifiedSince(ifmodifiedsince);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Sets the default value of the <code>useCaches</code> field to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param   defaultusecaches   the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public void setDefaultUseCaches(boolean defaultusecaches) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the default value of a <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <code>useCaches</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Ths default is "sticky", being a part of the static state of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * URLConnections.  This flag applies to the next, and all following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * URLConnections that are created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return  the default value of a <code>URLConnection</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *          <code>useCaches</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see     java.net.URLConnection#useCaches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public boolean getDefaultUseCaches() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return jarFileURLConnection.getDefaultUseCaches();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}