tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1384104 - in /tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources: FileResource.java JarResource.java LocalStrings.properties ResourceBase.java
Date Wed, 12 Sep 2012 20:04:02 GMT
Author: markt
Date: Wed Sep 12 20:04:01 2012
New Revision: 1384104

URL: http://svn.apache.org/viewvc?rev=1384104&view=rev
Log:
Implement a TODO:
 - getContent()

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java?rev=1384104&r1=1384103&r2=1384104&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/FileResource.java
Wed Sep 12 20:04:01 2012
@@ -122,12 +122,6 @@ public class FileResource extends Resour
     }
 
     @Override
-    public byte[] getContent() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public long getCreation() {
         try {
             BasicFileAttributes attrs = Files.readAttributes(resource.toPath(),
@@ -162,4 +156,9 @@ public class FileResource extends Resour
     protected File getResourceInternal() {
         return resource;
     }
+
+    @Override
+    protected Log getLog() {
+        return log;
+    }
 }

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java?rev=1384104&r1=1384103&r2=1384104&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java
Wed Sep 12 20:04:01 2012
@@ -121,12 +121,6 @@ public class JarResource extends Resourc
     }
 
     @Override
-    public byte[] getContent() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public long getCreation() {
         return resource.getTime();
     }
@@ -143,4 +137,9 @@ public class JarResource extends Resourc
             return null;
         }
     }
+
+    @Override
+    protected Log getLog() {
+        return log;
+    }
 }

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1384104&r1=1384103&r2=1384104&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
Wed Sep 12 20:04:01 2012
@@ -19,3 +19,6 @@ fileResource.getUrlFail=Unable to determ
 
 jarResource.getInputStreamFail=Unable to obtain an InputStream for the resource [{0}] located
in the JAR [{1}]
 jarResource.getUrlFail=Unable to determine a URL for the resource [{0}] located in the JAR
[{1}]
+
+resourceBase.getContentFail=Unable to return [{0}] as a byte array
+resourceBase.getContentTooLarge=Unable to return [{0}] as a byte array since the resource
is [{1}] bytes in size which is larger than the maximum size of a byte array
\ No newline at end of file

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java?rev=1384104&r1=1384103&r2=1384104&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/ResourceBase.java
Wed Sep 12 20:04:01 2012
@@ -16,8 +16,12 @@
  */
 package org.apache.catalina.webresources;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.apache.catalina.WebResource;
 import org.apache.catalina.WebResourceRoot;
+import org.apache.juli.logging.Log;
 import org.apache.tomcat.util.res.StringManager;
 
 public abstract class ResourceBase implements WebResource {
@@ -59,4 +63,47 @@ public abstract class ResourceBase imple
     public final String getMimeType() {
         return mimeType;
     }
+
+
+    @Override
+    public final byte[] getContent() {
+        long len = getContentLength();
+
+        if (len > Integer.MAX_VALUE) {
+            // Can't create an array that big
+            throw new ArrayIndexOutOfBoundsException(sm.getString(
+                    "resourceBase.getContentTooLarge", getWebappPath(),
+                    Long.valueOf(len)));
+        }
+
+        int size = (int) len;
+        byte[] result = new byte[size];
+
+        InputStream is = getInputStream();
+
+        if (is == null) {
+            return null;
+        }
+
+        int pos = 0;
+        try {
+            while (pos < size) {
+                int n = is.read(result, pos, size - pos);
+                if (n < 0) {
+                    break;
+                }
+                pos += n;
+            }
+        } catch (IOException ioe) {
+            if (getLog().isDebugEnabled()) {
+                getLog().debug(sm.getString("resourceBase.getContentFail",
+                        getWebappPath()), ioe);
+            }
+        }
+
+        return result;
+    }
+
+
+    protected abstract Log getLog();
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message