Author: michiel
Date: 2010-03-02 17:02:48 +0100 (Tue, 02 Mar 2010)
New Revision: 41229

Modified:
   mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/MimeType.java
   
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
Log:
introduced the concept of 'unknown' mimetype, which is something different than 
'octetstream'

Modified: 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/MimeType.java
===================================================================
--- mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/MimeType.java 
2010-03-02 14:22:11 UTC (rev 41228)
+++ mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/MimeType.java 
2010-03-02 16:02:48 UTC (rev 41229)
@@ -10,9 +10,12 @@
 package org.mmbase.util;
 
 /**
+ * Representation of a 'mimetype'  (or <a 
href="http://en.wikipedia.org/wiki/Internet_media_type";>Internet media 
type</a>). A pair of two
+ * strings, together more or less representing the 'type' of a certain binary 
blob. We support also wild cards with {...@link #STAR}, especially when using
+ * {...@link #matches(MimeType)}
  *
  * @author Michiel Meeuwissen
- * @since MMBase-2.0
+ * @since MMBase-1.9.3
  */
 
 public class MimeType implements java.io.Serializable {
@@ -20,7 +23,8 @@
 
     public static final String STAR = "*";
     public static final MimeType ANY = new MimeType(STAR, STAR);
-    public static final MimeType OCTETSTREAM = new MimeType("application", 
"octet-stream");
+    public static final MimeType OCTETSTREAM  = new MimeType("application", 
"octet-stream");
+    public static final MimeType UNDETERMINED = new MimeType("unknown", 
"unknown");
 
     private final String type;
     private final String subType;

Modified: 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
  2010-03-02 14:22:11 UTC (rev 41228)
+++ 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
  2010-03-02 16:02:48 UTC (rev 41229)
@@ -55,7 +55,7 @@
     private long fileMark = 0;
     private boolean tempFile = true;
     private String name;
-    private String contentType = null;
+    private MimeType contentType = null;
     private transient InputStream wrapped;
     private boolean used = false;
 
@@ -80,10 +80,13 @@
         this.size = tempFile.length();
         this.name = name;
         if (tempFile.length() > 0) {
-            this.contentType = MagicFile.getInstance().getMimeType(tempFile);
-            if (MagicFile.FAILED.equals(this.contentType)) {
+            String ct = MagicFile.getInstance().getMimeType(tempFile);
+            if (MagicFile.FAILED.equals(ct)) {
                 log.warn("Failed to determin type of " + tempFile);
-                this.contentType = null;
+                this.contentType = MimeType.UNDETERMINED;
+            } else {
+                this.contentType = new MimeType(ct);
+
             }
         }
     }
@@ -100,11 +103,13 @@
         this.name = null;
         if (array.length > 0) {
             try {
-                this.contentType = MagicFile.getInstance().getMimeType(array);
+                String ct = MagicFile.getInstance().getMimeType(array);
 
-                if (MagicFile.FAILED.equals(this.contentType)) {
+                if (MagicFile.FAILED.equals(ct)) {
                     log.warn("Failed to determin type of byte array");
-                    this.contentType = null;
+                    this.contentType = MimeType.UNDETERMINED;
+                } else {
+                    this.contentType = new MimeType(ct);
                 }
             } catch (Exception e) {
             }
@@ -114,7 +119,7 @@
     public SerializableInputStream(FileItem fi) throws IOException {
         this.size = fi.getSize();
         this.name = fi.getName();
-        this.contentType = fi.getContentType();
+        this.contentType = new MimeType(fi.getContentType());
         file = File.createTempFile(getClass().getName(), this.name);
         file.deleteOnExit();
         try {
@@ -176,12 +181,12 @@
     }
 
     public String getContentType() {
-        return contentType;
+        return contentType == null ? null : contentType.toString();
     }
     /**
      * @since MMBase-1.9.3
      */
-    public void setContentType(String ct) {
+    public void setContentType(MimeType ct) {
         contentType = ct;
     }
     public synchronized byte[] get() throws IOException {
@@ -268,7 +273,7 @@
         wrapped = new ByteArrayInputStream(b);
         size = b.length;
         name = (String) oin.readObject();
-        contentType = (String) oin.readObject();
+        contentType = (MimeType) oin.readObject();
     }
     private void readObject(java.io.ObjectInputStream oin) throws IOException, 
ClassNotFoundException {
         _readObject(oin);

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to