Author: sshyrkov
Date: Tue Nov 20 22:21:36 2007
New Revision: 19240
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19240&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-4-1-BRANCH/src/java/org/jahia/services/applications/Stri=
ngServletOutputStream.java
Modified: branches/JAHIA-4-1-BRANCH/src/java/org/jahia/services/application=
s/StringServletOutputStream.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-4-1-BR=
ANCH/src/java/org/jahia/services/applications/StringServletOutputStream.jav=
a&rev=3D19240&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-4-1-BRANCH/src/java/org/jahia/services/applications/Stri=
ngServletOutputStream.java (original)
+++ branches/JAHIA-4-1-BRANCH/src/java/org/jahia/services/applications/Stri=
ngServletOutputStream.java Tue Nov 20 22:21:36 2007
@@ -43,7 +43,6 @@
import javax.servlet.ServletOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
=
/**
@@ -59,162 +58,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) {
@@ -222,22 +81,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);
}
@@ -245,8 +88,6 @@
public void flush ()
throws IOException {
if (existingStream !=3D null) {
- logger.debug ("Flushing pass-through stream...");
- existingStreamWriter.flush ();
existingStream.flush ();
}
}
@@ -254,4 +95,17 @@
public void close () {
}
=
-}
+ 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);
+ }
+ }
+
+ 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