Author: sshyrkov
Date: Tue Nov 20 21:58:31 2007
New Revision: 19239

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19239&repname=
=3Djahia
Log:
Gained performance boost by overriding two write() methods, that use writin=
g of array of bytes, instead of writing them byte-by-byte

Modified:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/appl=
ications/StringServletOutputStream.java

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/service=
s/applications/StringServletOutputStream.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/services/applications/StringServletOut=
putStream.java&rev=3D19239&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/appl=
ications/StringServletOutputStream.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/appl=
ications/StringServletOutputStream.java Tue Nov 20 21:58:31 2007
@@ -21,7 +21,6 @@
 import javax.servlet.ServletOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 =

 /**
@@ -37,162 +36,22 @@
  */
 public class StringServletOutputStream extends ServletOutputStream {
 =

-    private static org.apache.log4j.Logger logger =3D
-            org.apache.log4j.Logger.getLogger (StringServletOutputStream.c=
lass);
-
-    private ByteArrayOutputStream byteArray =3D new ByteArrayOutputStream =
();
-    private OutputStreamWriter streamWriter;
+    private ByteArrayOutputStream byteArray =3D new ByteArrayOutputStream(=
4096);
     private ServletOutputStream existingStream;
-    private OutputStreamWriter existingStreamWriter;
     private String encoding;
 =

     public StringServletOutputStream (String encoding) throws UnsupportedE=
ncodingException {
         super ();
         this.encoding =3D encoding;
-        streamWriter =3D new OutputStreamWriter (byteArray, encoding);
     }
 =

     public StringServletOutputStream (ServletOutputStream existingStream, =
String encoding)
             throws UnsupportedEncodingException {
-        super ();
+        this(encoding);
         this.existingStream =3D existingStream;
-        this.encoding =3D encoding;
-        streamWriter =3D new OutputStreamWriter (byteArray, encoding);
-        existingStreamWriter =3D new OutputStreamWriter (existingStream, e=
ncoding);
-    }
-
-    /*
-    public void print(boolean b) {
-        try {
-            Boolean bol =3D new Boolean(b);
-            streamWriter.write(bol.toString());
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
     }
 =

-    public void print(char c) {
-        try {
-            streamWriter.write(c);
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(char[] s) {
-        try {
-            streamWriter.write(s);
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(double d) {
-        try {
-            streamWriter.write(Double.toString(d));
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(float f) {
-        try {
-            streamWriter.write(Float.toString(f));
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(int i) {
-        try {
-            streamWriter.write(i);
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(long l) {
-        try {
-            streamWriter.write(Long.toString(l));
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void print(String s) {
-        try {
-            streamWriter.write(s);
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void println() {
-        try {
-            streamWriter.write("\n");
-        } catch (java.io.IOException ioe) {
-            logger.warn (ioe);
-        }
-    }
-
-    public void println(boolean b) {
-        this.print(b);
-        this.println();
-    }
-
-    public void println(char c) {
-        this.print(c);
-        this.println();
-    }
-
-    public void println(char[] s) {
-        this.print(s);
-        this.println();
-    }
-
-    public void println(double d) {
-        this.print(d);
-        this.println();
-    }
-
-    public void println(float f) {
-        this.print(f);
-        this.println();
-    }
-
-    public void println(int i) {
-        this.print(i);
-        this.println();
-    }
-
-    public void println(long l) {
-        this.print(l);
-        this.println();
-    }
-
-
-    public void println(String x) {
-        this.print(x);
-        this.println();
-    }
-*/
-    public void write (char[] cbuf)
-            throws IOException {
-        streamWriter.write (cbuf, 0, cbuf.length);
-        if (existingStream !=3D null) {
-            existingStreamWriter.write (cbuf, 0, cbuf.length);
-        }
-    }
-
-    public void write (char[] cbuf, int off, int len)
-            throws IOException {
-        streamWriter.write (cbuf, off, len);
-        if (existingStream !=3D null) {
-            existingStreamWriter.write (cbuf, off, len);
-        }
-    }
-
-    public void write (int c)
+   public void write (int c)
             throws IOException {
         byteArray.write (c);
         if (existingStream !=3D null) {
@@ -200,22 +59,6 @@
         }
     }
 =

-    public void write (String s)
-            throws IOException {
-        streamWriter.write (s);
-        if (existingStream !=3D null) {
-            existingStreamWriter.write (s);
-        }
-    }
-
-    public void write (String str, int off, int len)
-            throws IOException {
-        streamWriter.write (str, off, len);
-        if (existingStream !=3D null) {
-            existingStreamWriter.write (str, off, len);
-        }
-    }
-
     public String getBuffer () throws UnsupportedEncodingException {
         return byteArray.toString (encoding);
     }
@@ -223,8 +66,6 @@
     public void flush ()
             throws IOException {
         if (existingStream !=3D null) {
-            logger.debug ("Flushing pass-through stream...");
-            existingStreamWriter.flush ();
             existingStream.flush ();
         }
     }
@@ -232,4 +73,19 @@
     public void close () {
     }
 =

-}
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        byteArray.write(b, off, len);
+        if (existingStream !=3D null) {
+            existingStream.write(b, off, len);
+        }
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        byteArray.write(b);
+        if (existingStream !=3D null) {
+            existingStream.write(b);
+        }
+    }
+}
\ No newline at end of file

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to