Author: michiel
Date: 2010-02-15 17:58:41 +0100 (Mon, 15 Feb 2010)
New Revision: 41021
Modified:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
Log:
ported some stuff from trunk
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-02-15 16:41:15 UTC (rev 41020)
+++
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/util/SerializableInputStream.java
2010-02-15 16:58:41 UTC (rev 41021)
@@ -12,6 +12,7 @@
import java.io.*;
import org.mmbase.util.logging.*;
+import org.mmbase.util.magicfile.MagicFile;
import org.apache.commons.fileupload.FileItem;
/**
@@ -54,7 +55,7 @@
private long fileMark = 0;
private boolean tempFile = true;
private String name;
- private String contentType;
+ private String contentType = null;
private transient InputStream wrapped;
private boolean used = false;
@@ -62,7 +63,9 @@
this.wrapped = wrapped;
this.size = s;
this.name = null;
- if (wrapped == null) throw new NullPointerException();
+ if (wrapped == null) {
+ throw new NullPointerException();
+ }
if (wrapped.markSupported()) {
wrapped.mark(Integer.MAX_VALUE);
}
@@ -76,6 +79,13 @@
this.wrapped = new FileInputStream(tempFile);
this.size = tempFile.length();
this.name = name;
+ if (tempFile.length() > 0) {
+ this.contentType = MagicFile.getInstance().getMimeType(tempFile);
+ if (MagicFile.FAILED.equals(this.contentType)) {
+ log.warn("Failed to determin type of " + tempFile);
+ this.contentType = null;
+ }
+ }
}
/**
* @since MMBase-1.9.2
@@ -88,6 +98,17 @@
wrapped = new ByteArrayInputStream(array);
this.size = array.length;
this.name = null;
+ if (array.length > 0) {
+ try {
+ this.contentType = MagicFile.getInstance().getMimeType(array);
+
+ if (MagicFile.FAILED.equals(this.contentType)) {
+ log.warn("Failed to determin type of byte array");
+ this.contentType = null;
+ }
+ } catch (Exception e) {
+ }
+ }
}
public SerializableInputStream(FileItem fi) throws IOException {
@@ -157,6 +178,12 @@
public String getContentType() {
return contentType;
}
+ /**
+ * @since MMBase-1.9.3
+ */
+ public void setContentType(String ct) {
+ contentType = ct;
+ }
public synchronized byte[] get() throws IOException {
if (wrapped == null) {
throw new IllegalStateException();
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs