User: starksm 
  Date: 01/11/03 22:53:32

  Modified:    src/main/org/jboss/mq SpyTextMessage.java
  Log:
  Since the ObjectInput.available() may be <= 0 check for this and
  default to a small message size of 256 bytes.
  
  Revision  Changes    Path
  1.6       +52 -20    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SpyTextMessage.java       2001/11/02 23:06:46     1.5
  +++ SpyTextMessage.java       2001/11/04 06:53:31     1.6
  @@ -18,11 +18,12 @@
    *
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.5 $
  + * @version    $Revision: 1.6 $
    */
   public class SpyTextMessage
          extends SpyMessage
  -       implements Cloneable, TextMessage, Externalizable {
  +       implements Cloneable, TextMessage, Externalizable
  +{
   
      // Attributes ----------------------------------------------------
   
  @@ -34,26 +35,31 @@
      // Public --------------------------------------------------------
   
      public void setText( String string )
  -      throws JMSException {
  -      if ( header.msgReadOnly ) {
  +      throws JMSException
  +   {
  +      if ( header.msgReadOnly )
  +      {
            throw new MessageNotWriteableException( "Cannot set the content" );
         }
         content = string;
      }
   
      public String getText()
  -      throws JMSException {
  +      throws JMSException
  +   {
         return content;
      }
   
      public void clearBody()
  -      throws JMSException {
  +      throws JMSException
  +   {
         content = null;
         super.clearBody();
      }
   
      public SpyMessage myClone()
  -      throws JMSException {
  +      throws JMSException
  +   {
         SpyTextMessage result = new SpyTextMessage();
         result.copyProps( this );
         result.content = this.content;
  @@ -61,12 +67,16 @@
      }
   
      public void readExternal( java.io.ObjectInput in )
  -      throws java.io.IOException, ClassNotFoundException {
  +      throws java.io.IOException, ClassNotFoundException
  +   {
         super.readExternal( in );
         byte type = in.readByte();
  -      if ( type == NULL ) {
  +      if ( type == NULL )
  +      {
            content = null;
  -      } else {
  +      }
  +      else
  +      { 
            // apply workaround for string > 64K bug in jdk's 1.3.*
   
            // Read the no. of chunks this message is split into, allocate
  @@ -75,9 +85,21 @@
            int chunksToRead = in.readInt();
         int bufferSize = chunkSize * chunksToRead;
         if(chunksToRead <= 1)
  -            bufferSize = Math.min(in.available(), bufferSize);
  +         {
  +            /* The text size is likely to be much smaller than the chunkSize
  +               so set bufferSize to the min of the input stream available
  +               and the maximum buffer size. Since the input stream
  +               available() can be <= 0 we check for that and default to
  +               a small msg size of 256 bytes.
  +            */
  +            int inSize = in.available();
  +            if( inSize <= 0 )
  +               inSize = 256;
  +            bufferSize = Math.min(inSize, bufferSize);
  +         }
            StringBuffer sb = new StringBuffer(bufferSize);
  -         for (int i = 0; i < chunksToRead; i++) {
  +         for (int i = 0; i < chunksToRead; i++)
  +         {
               sb.append( in.readUTF() );
            }
            content = sb.toString();
  @@ -85,11 +107,15 @@
      }
   
      public void writeExternal( java.io.ObjectOutput out )
  -      throws java.io.IOException {
  +      throws java.io.IOException
  +   {
         super.writeExternal( out );
  -      if ( content == null ) {
  +      if ( content == null )
  +      {
            out.writeByte( NULL );
  -      } else {
  +      }
  +      else
  +      {
            // apply workaround for string > 64K bug in jdk's 1.3.*
   
            // Split content into chunks of size 'chunkSize' and assemble
  @@ -97,7 +123,8 @@
            ArrayList v = new ArrayList();
            int contentLength = content.length();
   
  -         while (contentLength > 0) {
  +         while (contentLength > 0)
  +         {
               int beginCopy = (v.size()) * chunkSize;
               int endCopy = contentLength <= chunkSize ?
                  beginCopy + contentLength : beginCopy + chunkSize;
  @@ -112,7 +139,8 @@
            // all chunks that have been assembled previously
            out.writeByte( OBJECT );
            out.writeInt(v.size());
  -         for (int i = 0; i < v.size(); i++) {
  +         for (int i = 0; i < v.size(); i++)
  +         {
               out.writeUTF( (String)v.get(i) );
            }
         }
  @@ -120,10 +148,14 @@
   
      // Object override -----------------------------------------------
   
  -   public String toString() {
  -      try {
  +   public String toString()
  +   {
  +      try
  +      {
            return "TextMessage@" + getText();
  -      } catch ( JMSException e ) {
  +      }
  +      catch ( JMSException e )
  +      {
            return "toString() failed !";
         }
      }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to