You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2006/01/09 18:37:42 UTC

svn commit: r367348 - in /xml/security/trunk/src/org/apache/xml/security/utils: UnsyncBufferedOutputStream.java UnsyncByteArrayOutputStream.java

Author: raul
Date: Mon Jan  9 09:37:38 2006
New Revision: 367348

URL: http://svn.apache.org/viewcvs?rev=367348&view=rev
Log:
	Use a ThreadLocal buffer in order to reduce instancation time.

Modified:
    xml/security/trunk/src/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java
    xml/security/trunk/src/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java

Modified: xml/security/trunk/src/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java
URL: http://svn.apache.org/viewcvs/xml/security/trunk/src/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java?rev=367348&r1=367347&r2=367348&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java Mon Jan  9 09:37:38 2006
@@ -26,8 +26,14 @@
  */
 public class UnsyncBufferedOutputStream extends OutputStream {
 	final OutputStream out;
+	
+	final byte[] buf=(byte[])bufCahce.get();
 	static final int size=8*1024;
-	final byte[] buf=new byte[size];
+	private static ThreadLocal bufCahce = new ThreadLocal() {
+        protected synchronized Object initialValue() {
+            return new byte[size];
+        }
+    };
 	int pointer=0;
 	/**
 	 * Creates a buffered output stream without synchronization
@@ -81,7 +87,7 @@
 
 	/** @inheritDoc */
 	public void close() throws IOException {
-		flush();		
+		flush();				
 	}
 
 }

Modified: xml/security/trunk/src/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
URL: http://svn.apache.org/viewcvs/xml/security/trunk/src/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java?rev=367348&r1=367347&r2=367348&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java Mon Jan  9 09:37:38 2006
@@ -16,18 +16,25 @@
  */
 package org.apache.xml.security.utils;
 
-import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
 
 /**
  * A simple Unsynced ByteArryOutputStream
  * @author raul
  *
  */
-public class UnsyncByteArrayOutputStream extends ByteArrayOutputStream {
-	int size=4*1024;
-	byte []buf=new byte[size];
-	int pos;
+public class UnsyncByteArrayOutputStream extends OutputStream  {	
+	private static ThreadLocal bufCahce = new ThreadLocal() {
+        protected synchronized Object initialValue() {
+            return new byte[8*1024];
+        }        
+    };
+    byte[] buf=(byte[])bufCahce.get();
+	int size=8*1024;//buf.length;	
+	int pos=0;
 	/** @inheritDoc */
+	public UnsyncByteArrayOutputStream() {	
+	}
 	public void write(byte[] arg0) {
 		int newPos=pos+arg0.length;
 		if (newPos>size) {
@@ -68,7 +75,7 @@
 	void expandSize() {
 		int newSize=size<<2;
 		byte newBuf[]=new byte[newSize];
-		System.arraycopy(buf,0,newBuf,0,pos);
+		System.arraycopy(buf,0,newBuf,0,pos);		
 		buf=newBuf;
 		size=newSize;