User: dmaplesden
  Date: 01/09/17 14:09:46

  Modified:    src/main/org/jboss/mq SpyTextMessage.java
  Log:
  Apply submitted patch for working around write/read utf limitation in jdk 1.3.*
  
  Revision  Changes    Path
  1.3       +39 -4     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SpyTextMessage.java       2001/08/17 03:04:01     1.2
  +++ SpyTextMessage.java       2001/09/17 21:09:46     1.3
  @@ -7,6 +7,7 @@
   package org.jboss.mq;
   
   import java.io.*;
  +import java.util.ArrayList;
   import javax.jms.JMSException;
   import javax.jms.MessageNotWriteableException;
   
  @@ -17,7 +18,7 @@
    *
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @created    August 16, 2001
  - * @version    $Revision: 1.2 $
  + * @version    $Revision: 1.3 $
    */
   public class SpyTextMessage
          extends SpyMessage
  @@ -28,7 +29,8 @@
      String           content = null;
   
      private final static long serialVersionUID = 235726945332013953L;
  -
  +   private final static int chunkSize = 16384;
  + 
      // Public --------------------------------------------------------
   
      public void setText( String string )
  @@ -65,7 +67,17 @@
         if ( type == NULL ) {
            content = null;
         } else {
  -         content = in.readUTF();
  +         // apply workaround for string > 64K bug in jdk's 1.3.*
  +
  +         // Read the no. of chunks this message is split into, allocate
  +         // 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);
  +         for (int i = 0; i < chunksToRead; i++) {
  +            sb.append( in.readUTF() );
  +         }
  +         content = sb.toString();
         }
      }
   
  @@ -75,8 +87,31 @@
         if ( content == null ) {
            out.writeByte( NULL );
         } else {
  +         // apply workaround for string > 64K bug in jdk's 1.3.*
  +
  +         // Split content into chunks of size 'chunkSize' and assemble
  +         // the pieces into a Vector ...
  +         ArrayList v = new ArrayList();
  +         int contentLength = content.length();
  +
  +         while (contentLength > 0) {
  +            int beginCopy = (v.size()) * chunkSize;
  +            int endCopy = contentLength <= chunkSize ?
  +               beginCopy + contentLength : beginCopy + chunkSize;
  +
  +            String theChunk = content.substring(beginCopy, endCopy);
  +            v.add(theChunk);
  +
  +            contentLength -= chunkSize;
  +         }
  +
  +         // Write out the type (OBJECT), the no. of chunks and finally
  +         // all chunks that have been assembled previously
            out.writeByte( OBJECT );
  -         out.writeUTF( content );
  +         out.writeInt(v.size());
  +         for (int i = 0; i < v.size(); i++) {
  +            out.writeUTF( (String)v.get(i) );
  +         }
         }
      }
   
  
  
  

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

Reply via email to