HI,

In PlainTextResult had a bit dead code.

Attached is a small patch which fixes that. It working now, but it
could be more optimal: no need to create inputstreams if the
getResourceAsStream returns null. But this should be the exception
anyway.

Cheers,
Christian
### Eclipse Workspace Patch 1.0
#P struts2-core
Index: src/main/java/org/apache/struts2/dispatcher/PlainTextResult.java
===================================================================
--- src/main/java/org/apache/struts2/dispatcher/PlainTextResult.java    
(revision 1096678)
+++ src/main/java/org/apache/struts2/dispatcher/PlainTextResult.java    
(working copy)
@@ -21,6 +21,7 @@
 
 package org.apache.struts2.dispatcher;
 
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.nio.charset.Charset;
@@ -141,16 +142,16 @@
         PrintWriter writer = response.getWriter();
         InputStreamReader reader = null;
         try {
+               InputStream resourceAsStream = 
servletContext.getResourceAsStream(finalLocation);
             if (charset != null) {
-                reader = new 
InputStreamReader(servletContext.getResourceAsStream(finalLocation), charset);
+                reader = new InputStreamReader(resourceAsStream, charset);
             }
             else {
-                reader = new 
InputStreamReader(servletContext.getResourceAsStream(finalLocation));
+                reader = new InputStreamReader(resourceAsStream);
             }
-            if (reader == null) {
-                LOG.warn("resource at location ["+finalLocation+"] cannot be 
obtained (return null) from ServletContext !!! ");
-            }
-            else {
+            if (resourceAsStream == null) {
+               LOG.warn("resource at location ["+finalLocation+"] cannot be 
obtained (return null) from ServletContext !!! ");
+            } else {
                 char[] buffer = new char[BUFFER_SIZE];
                 int charRead = 0;
                 while((charRead = reader.read(buffer)) != -1) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to