User: weave Date: 01/11/02 15:06:47 Modified: src/main/org/jboss/mq SpyTextMessage.java Log: Modified the readExternl() method to check the number of available chunks. If there is only one chuck available then the initial capacity of the StringBuffer is set to the number of available bytes. This was necessary to avoid small messages from allocating large buffers. In addition when testing with the IBM JDK the toString() method of the StringBuffer class appeared to implement a copy-on-write char[] sharing. This meant that if a large buffer was allocate it would not be reduced to the message size since the StringBuffer was not modified after the toString() call. I'm still concerned that if the last chunk is realitively small then there may be a fair amount of wasted space. This would become a smaller precent as the number of chunks grow. Revision Changes Path 1.5 +5 -2 jbossmq/src/main/org/jboss/mq/SpyTextMessage.java Index: SpyTextMessage.java =================================================================== RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/SpyTextMessage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SpyTextMessage.java 2001/10/28 04:07:34 1.4 +++ SpyTextMessage.java 2001/11/02 23:06:46 1.5 @@ -18,7 +18,7 @@ * * @author Norbert Lataille ([EMAIL PROTECTED]) * @created August 16, 2001 - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class SpyTextMessage extends SpyMessage @@ -73,7 +73,10 @@ // a StringBuffer that can hold all chunks, read the chunks // into the buffer and set 'content' accordingly int chunksToRead = in.readInt(); - StringBuffer sb = new StringBuffer(chunkSize * chunksToRead); + int bufferSize = chunkSize * chunksToRead; + if(chunksToRead <= 1) + bufferSize = Math.min(in.available(), bufferSize); + StringBuffer sb = new StringBuffer(bufferSize); for (int i = 0; i < chunksToRead; i++) { sb.append( in.readUTF() ); }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development