You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ec...@apache.org on 2019/11/07 16:58:21 UTC

[commons-vfs] branch master updated: Share FileContentInfo in FileContentInfoFilenameFactory.

This is an automated email from the ASF dual-hosted git repository.

ecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new b6fb9a3  Share FileContentInfo in FileContentInfoFilenameFactory.
b6fb9a3 is described below

commit b6fb9a392d9510ce039e55a26a47ed85750a4386
Author: Bernd Eckenfels <ec...@apache.org>
AuthorDate: Thu Nov 7 17:56:12 2019 +0100

    Share FileContentInfo in FileContentInfoFilenameFactory.
    
    For the common case that no content-type information is available avoid
    proliferation of DefaultFileContentInfo instances.
---
 .../commons/vfs2/impl/FileContentInfoFilenameFactory.java      | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileContentInfoFilenameFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileContentInfoFilenameFactory.java
index afe38ba..2888ff6 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileContentInfoFilenameFactory.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/FileContentInfoFilenameFactory.java
@@ -29,6 +29,9 @@ import org.apache.commons.vfs2.FileContentInfoFactory;
  * Uses the file name extension to determine the content-type. The content-encoding is not resolved.
  */
 public class FileContentInfoFilenameFactory implements FileContentInfoFactory {
+
+    private static final FileContentInfo NULL_INFO = new DefaultFileContentInfo(null, null);
+
     @Override
     public FileContentInfo create(final FileContent fileContent) {
         String contentType = null;
@@ -39,6 +42,11 @@ public class FileContentInfoFilenameFactory implements FileContentInfoFactory {
             contentType = fileNameMap.getContentTypeFor(name);
         }
 
-        return new DefaultFileContentInfo(contentType, null);
+        // optimize object creation for common case
+        if (contentType == null) {
+            return NULL_INFO;
+        } else {
+            return new DefaultFileContentInfo(contentType, null);
+        }
     }
 }