This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[4.1] Patch: FYI: PR 27024


This fixes PR 27024 for the 4.1 branch.

For the trunk I am working on a different fix, which involves merging
away our divergences here and simply using Classpath's URLConnection.

Tom

Index: classpath/ChangeLog.gcj
from  Tom Tromey  <tromey@redhat.com>
	PR libgcj/27024:
	* java/net/MimeTypeMapper.java (getContentTypeFor): Fall back
	to MimeTypes.

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR libgcj/27024:
	* java/net/URLConnection.java (guessContentTypeFromName):
	Rewrote, using Classpath implementation.
	(getFileNameMap): Likewise.
	(guessContentTypeFromStream): Return application/octet-stream.

Index: java/net/URLConnection.java
===================================================================
--- java/net/URLConnection.java	(revision 112683)
+++ java/net/URLConnection.java	(working copy)
@@ -1,5 +1,5 @@
 /* URLConnection.java -- Abstract superclass for reading from URL's
-   Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -899,22 +899,7 @@
    */
   public static String guessContentTypeFromName(String filename)
   {
-    int dot = filename.lastIndexOf(".");
-    
-    if (dot != -1)
-      {
-	if (dot == filename.length())
-	  return "application/octet-stream";
-	else
-	  filename = filename.substring(dot + 1);
-      }
-    
-    String type = MimeTypes.getMimeTypeFromExtension(filename);
-    
-    if (type == null)
-      return"application/octet-stream";
-
-    return type;
+    return getFileNameMap().getContentTypeFor(filename.toLowerCase());
   }
 
   /**
@@ -939,7 +924,7 @@
     is.mark(1024);
     // FIXME: Implement this. Use system mimetype informations (like "file").
     is.reset();
-    return null;
+    return "application/octet-stream";
   }
 
   /**
@@ -950,8 +935,12 @@
    *
    * @since 1.2
    */
-  public static FileNameMap getFileNameMap()
+  public static synchronized FileNameMap getFileNameMap()
   {
+    // Delayed initialization.
+    if (fileNameMap == null)
+      fileNameMap = new MimeTypeMapper();
+
     return fileNameMap;
   }
 
@@ -966,7 +955,7 @@
    *
    * @since 1.2
    */
-  public static void setFileNameMap(FileNameMap map)
+  public static synchronized void setFileNameMap(FileNameMap map)
   {
     // Throw an exception if an extant security manager precludes
     // setting the factory.
Index: classpath/java/net/MimeTypeMapper.java
===================================================================
--- classpath/java/net/MimeTypeMapper.java	(revision 112683)
+++ classpath/java/net/MimeTypeMapper.java	(working copy)
@@ -1,5 +1,5 @@
 /* MimeTypeMapper.java -- A class for mapping file names to MIME types
-   Copyright (C) 1998 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -38,6 +38,7 @@
 package java.net;
 
 import java.util.Hashtable;
+import gnu.gcj.io.MimeTypes;
 
 
 /**
@@ -206,7 +207,7 @@
 
     String type = (String) mime_types.get(filename);
     if (type == null)
-      return "application/octet-stream";
+      return MimeTypes.getMimeTypeFromExtension(filename);
     else
       return type;
   }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]