You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/02/28 14:31:22 UTC

svn commit: r631966 - /incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java

Author: fmeschbe
Date: Thu Feb 28 05:31:12 2008
New Revision: 631966

URL: http://svn.apache.org/viewvc?rev=631966&view=rev
Log:
SLING-288 Add new sling.contentLength meta data property and allow for it
to be set only after adapting the resource to an InputStream

Modified:
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java?rev=631966&r1=631965&r2=631966&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java (original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java Thu Feb 28 05:31:12 2008
@@ -52,6 +52,18 @@
     public static final String CONTENT_TYPE = "sling.contentType";
 
     /**
+     * The name of the optional property providing the content length of the
+     * resource if the resource is streamable (value is "sling.contentLength").
+     * This property may be missing if the resource is not streamable or if the
+     * content length is not known.
+     * <p>
+     * Note, that unlike the other properties, this property may be set only
+     * after the resource has successfully been adapted to an
+     * <code>InputStream</code> for performance reasons.
+     */
+    public static final String CONTENT_LENGTH = "sling.contentLength";
+
+    /**
      * The name of the optional property providing the character encoding of the
      * resource if the resource is streamable and contains character data (value
      * is "sling.characterEncoding"). This property may be missing if the
@@ -122,6 +134,29 @@
         }
 
         return null;
+    }
+
+    /**
+     * Sets the {@link #CONTENT_LENGTH} property to <code>contentType</code>
+     * if not <code>null</code>.
+     */
+    public void setContentLength(long contentLength) {
+        if (contentLength > 0) {
+            put(CONTENT_LENGTH, contentLength);
+        }
+    }
+
+    /**
+     * Returns the {@link #CONTENT_LENGTH} property if not <code>null</code>
+     * and a <code>long</code>. Otherwise <code>-1</code> is returned.
+     */
+    public long getContentLength() {
+        Object value = get(CONTENT_LENGTH);
+        if (value instanceof Long) {
+            return (Long) value;
+        }
+
+        return -1;
     }
 
     /**