< prev index next >

src/java.base/share/classes/java/net/URLConnection.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  26 package java.net;
  27 
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.io.OutputStream;
  31 import java.security.PrivilegedAction;
  32 import java.util.Hashtable;
  33 import java.util.Date;
  34 import java.util.Iterator;
  35 import java.util.Objects;
  36 import java.util.ServiceConfigurationError;
  37 import java.util.ServiceLoader;
  38 import java.util.StringTokenizer;
  39 import java.util.Collections;
  40 import java.util.Map;
  41 import java.util.List;
  42 import java.security.Permission;
  43 import java.security.AccessController;
  44 import sun.security.util.SecurityConstants;
  45 import sun.net.www.MessageHeader;

  46 
  47 /**
  48  * The abstract class {@code URLConnection} is the superclass
  49  * of all classes that represent a communications link between the
  50  * application and a URL. Instances of this class can be used both to
  51  * read from and to write to the resource referenced by the URL. In
  52  * general, creating a connection to a URL is a multistep process:
  53  *
  54  * <center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time.">
  55  * <tr><th>{@code openConnection()}</th>
  56  *     <th>{@code connect()}</th></tr>
  57  * <tr><td>Manipulate parameters that affect the connection to the remote
  58  *         resource.</td>
  59  *     <td>Interact with the resource; query header fields and
  60  *         contents.</td></tr>
  61  * </table>
  62  * ----------------------------&gt;
  63  * <br>time</center>
  64  *
  65  * <ol>


1378             if (c == '/') {
1379                 nm[i] = '.';
1380             } else if (!('A' <= c && c <= 'Z' ||
1381                        'a' <= c && c <= 'z' ||
1382                        '0' <= c && c <= '9')) {
1383                 nm[i] = '_';
1384             }
1385         }
1386         return new String(nm);
1387     }
1388 
1389 
1390     /**
1391      * Returns a vertical bar separated list of package prefixes for potential
1392      * content handlers.  Tries to get the java.content.handler.pkgs property
1393      * to use as a set of package prefixes to search.  Whether or not
1394      * that property has been defined, the {@value #contentClassPrefix}
1395      * is always the last one on the returned package list.
1396      */
1397     private String getContentHandlerPkgPrefixes() {
1398         String packagePrefixList = AccessController.doPrivileged(
1399             new sun.security.action.GetPropertyAction(contentPathProp, ""));
1400 
1401         if (packagePrefixList != "") {
1402             packagePrefixList += "|";
1403         }
1404 
1405         return packagePrefixList + contentClassPrefix;
1406     }
1407 
1408     /**
1409      * Tries to determine the content type of an object, based
1410      * on the specified "file" component of a URL.
1411      * This is a convenience method that can be used by
1412      * subclasses that override the {@code getContentType} method.
1413      *
1414      * @param   fname   a filename.
1415      * @return  a guess as to what the content type of the object is,
1416      *          based upon its file name.
1417      * @see     java.net.URLConnection#getContentType()
1418      */
1419     public static String guessContentTypeFromName(String fname) {




  26 package java.net;
  27 
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.io.OutputStream;
  31 import java.security.PrivilegedAction;
  32 import java.util.Hashtable;
  33 import java.util.Date;
  34 import java.util.Iterator;
  35 import java.util.Objects;
  36 import java.util.ServiceConfigurationError;
  37 import java.util.ServiceLoader;
  38 import java.util.StringTokenizer;
  39 import java.util.Collections;
  40 import java.util.Map;
  41 import java.util.List;
  42 import java.security.Permission;
  43 import java.security.AccessController;
  44 import sun.security.util.SecurityConstants;
  45 import sun.net.www.MessageHeader;
  46 import sun.security.action.GetPropertyAction;
  47 
  48 /**
  49  * The abstract class {@code URLConnection} is the superclass
  50  * of all classes that represent a communications link between the
  51  * application and a URL. Instances of this class can be used both to
  52  * read from and to write to the resource referenced by the URL. In
  53  * general, creating a connection to a URL is a multistep process:
  54  *
  55  * <center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time.">
  56  * <tr><th>{@code openConnection()}</th>
  57  *     <th>{@code connect()}</th></tr>
  58  * <tr><td>Manipulate parameters that affect the connection to the remote
  59  *         resource.</td>
  60  *     <td>Interact with the resource; query header fields and
  61  *         contents.</td></tr>
  62  * </table>
  63  * ----------------------------&gt;
  64  * <br>time</center>
  65  *
  66  * <ol>


1379             if (c == '/') {
1380                 nm[i] = '.';
1381             } else if (!('A' <= c && c <= 'Z' ||
1382                        'a' <= c && c <= 'z' ||
1383                        '0' <= c && c <= '9')) {
1384                 nm[i] = '_';
1385             }
1386         }
1387         return new String(nm);
1388     }
1389 
1390 
1391     /**
1392      * Returns a vertical bar separated list of package prefixes for potential
1393      * content handlers.  Tries to get the java.content.handler.pkgs property
1394      * to use as a set of package prefixes to search.  Whether or not
1395      * that property has been defined, the {@value #contentClassPrefix}
1396      * is always the last one on the returned package list.
1397      */
1398     private String getContentHandlerPkgPrefixes() {
1399         String packagePrefixList =
1400                 GetPropertyAction.getProperty(contentPathProp, "");
1401 
1402         if (packagePrefixList != "") {
1403             packagePrefixList += "|";
1404         }
1405 
1406         return packagePrefixList + contentClassPrefix;
1407     }
1408 
1409     /**
1410      * Tries to determine the content type of an object, based
1411      * on the specified "file" component of a URL.
1412      * This is a convenience method that can be used by
1413      * subclasses that override the {@code getContentType} method.
1414      *
1415      * @param   fname   a filename.
1416      * @return  a guess as to what the content type of the object is,
1417      *          based upon its file name.
1418      * @see     java.net.URLConnection#getContentType()
1419      */
1420     public static String guessContentTypeFromName(String fname) {


< prev index next >