diff -r 1c64f76edaa7 -r 9926996eca2d rt/emul/compact/src/main/java/java/net/URLConnection.java
--- a/rt/emul/compact/src/main/java/java/net/URLConnection.java Thu Oct 31 10:50:19 2013 +0100
+++ b/rt/emul/compact/src/main/java/java/net/URLConnection.java Thu Oct 31 11:23:54 2013 +0100
@@ -28,16 +28,17 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Hashtable;
+import java.io.PrintStream;
+import java.util.ArrayList;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
import java.util.List;
-import java.security.Permission;
-import java.security.AccessController;
-import sun.security.util.SecurityConstants;
-import sun.net.www.MessageHeader;
+import java.util.NoSuchElementException;
/**
* The abstract class URLConnection
is the superclass
@@ -314,7 +315,12 @@
*/
public static synchronized FileNameMap getFileNameMap() {
if ((fileNameMap == null) && !fileNameMapLoaded) {
- fileNameMap = sun.net.www.MimeTable.loadTable();
+ fileNameMap = new FileNameMap() {
+ @Override
+ public String getContentTypeFor(String fileName) {
+ return "text/plain";
+ }
+ };
fileNameMapLoaded = true;
}
@@ -342,9 +348,7 @@
* @since 1.2
*/
public static void setFileNameMap(FileNameMap map) {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) sm.checkSetFactory();
- fileNameMap = map;
+ throw new SecurityException();
}
/**
@@ -816,9 +820,9 @@
* requires network or file I/O and an exception occurs while
* computing it.
*/
- public Permission getPermission() throws IOException {
- return SecurityConstants.ALL_PERMISSION;
- }
+// public Permission getPermission() throws IOException {
+// return SecurityConstants.ALL_PERMISSION;
+// }
/**
* Returns an input stream that reads from this open connection.
@@ -1226,14 +1230,7 @@
* @see SecurityManager#checkSetFactory
*/
public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
- if (factory != null) {
- throw new Error("factory already defined");
- }
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkSetFactory();
- }
- factory = fac;
+ throw new SecurityException();
}
private static Hashtable handlers = new Hashtable();
@@ -1370,9 +1367,8 @@
* the last one on the returned package list.
*/
private String getContentHandlerPkgPrefixes() {
- String packagePrefixList = AccessController.doPrivileged(
- new sun.security.action.GetPropertyAction(contentPathProp, ""));
-
+ String packagePrefixList = "";
+
if (packagePrefixList != "") {
packagePrefixList += "|";
}
@@ -1795,3 +1791,524 @@
return uc.getInputStream();
}
}
+
+/** An RFC 844 or MIME message header. Includes methods
+ for parsing headers from incoming streams, fetching
+ values, setting values, and printing headers.
+ Key values of null are legal: they indicate lines in
+ the header that don't have a valid key, but do have
+ a value (this isn't legal according to the standard,
+ but lines like this are everywhere). */
+class MessageHeader {
+ private String keys[];
+ private String values[];
+ private int nkeys;
+
+ public MessageHeader () {
+ grow();
+ }
+
+ public MessageHeader (InputStream is) throws java.io.IOException {
+ parseHeader(is);
+ }
+
+ /**
+ * Reset a message header (all key/values removed)
+ */
+ public synchronized void reset() {
+ keys = null;
+ values = null;
+ nkeys = 0;
+ grow();
+ }
+
+ /**
+ * Find the value that corresponds to this key.
+ * It finds only the first occurrence of the key.
+ * @param k the key to find.
+ * @return null if not found.
+ */
+ public synchronized String findValue(String k) {
+ if (k == null) {
+ for (int i = nkeys; --i >= 0;)
+ if (keys[i] == null)
+ return values[i];
+ } else
+ for (int i = nkeys; --i >= 0;) {
+ if (k.equalsIgnoreCase(keys[i]))
+ return values[i];
+ }
+ return null;
+ }
+
+ // return the location of the key
+ public synchronized int getKey(String k) {
+ for (int i = nkeys; --i >= 0;)
+ if ((keys[i] == k) ||
+ (k != null && k.equalsIgnoreCase(keys[i])))
+ return i;
+ return -1;
+ }
+
+ public synchronized String getKey(int n) {
+ if (n < 0 || n >= nkeys) return null;
+ return keys[n];
+ }
+
+ public synchronized String getValue(int n) {
+ if (n < 0 || n >= nkeys) return null;
+ return values[n];
+ }
+
+ /** Deprecated: Use multiValueIterator() instead.
+ *
+ * Find the next value that corresponds to this key.
+ * It finds the first value that follows v. To iterate
+ * over all the values of a key use:
+ *
+ * for(String v=h.findValue(k); v!=null; v=h.findNextValue(k, v)) { + * ... + * } + *+ */ + public synchronized String findNextValue(String k, String v) { + boolean foundV = false; + if (k == null) { + for (int i = nkeys; --i >= 0;) + if (keys[i] == null) + if (foundV) + return values[i]; + else if (values[i] == v) + foundV = true; + } else + for (int i = nkeys; --i >= 0;) + if (k.equalsIgnoreCase(keys[i])) + if (foundV) + return values[i]; + else if (values[i] == v) + foundV = true; + return null; + } + + class HeaderIterator implements Iterator
ContentHandler
.
+ * @exception IOException if an I/O error occurs while reading the object.
+ */
+ abstract public Object getContent(URLConnection urlc) throws IOException;
+
+ /**
+ * Given a URL connect stream positioned at the beginning of the
+ * representation of an object, this method reads that stream and
+ * creates an object that matches one of the types specified.
+ *
+ * The default implementation of this method should call getContent()
+ * and screen the return type for a match of the suggested types.
+ *
+ * @param urlc a URL connection.
+ * @param classes an array of types requested
+ * @return the object read by the ContentHandler
that is
+ * the first match of the suggested types.
+ * null if none of the requested are supported.
+ * @exception IOException if an I/O error occurs while reading the object.
+ * @since 1.3
+ */
+ public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
+ Object obj = getContent(urlc);
+
+ for (int i = 0; i < classes.length; i++) {
+ if (classes[i].isInstance(obj)) {
+ return obj;
+ }
+ }
+ return null;
+ }
+
+}
+class UnknownServiceException extends IOException {
+ private static final long serialVersionUID = -4169033248853639508L;
+
+ /**
+ * Constructs a new UnknownServiceException
with no
+ * detail message.
+ */
+ public UnknownServiceException() {
+ }
+
+ /**
+ * Constructs a new UnknownServiceException
with the
+ * specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public UnknownServiceException(String msg) {
+ super(msg);
+ }
+}
+/**
+ * A simple interface which provides a mechanism to map
+ * between a file name and a MIME type string.
+ *
+ * @author Steven B. Byrne
+ * @since JDK1.1
+ */
+interface FileNameMap {
+
+ /**
+ * Gets the MIME type for the specified file name.
+ * @param fileName the specified file name
+ * @return a String
indicating the MIME
+ * type for the specified file name.
+ */
+ public String getContentTypeFor(String fileName);
+}