qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1618418 - in /qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client: BasicMessageProducer_0_10.java BasicMessageProducer_0_8.java
Date Sat, 16 Aug 2014 21:53:40 GMT
Author: rgodfrey
Date: Sat Aug 16 21:53:39 2014
New Revision: 1618418

URL: http://svn.apache.org/r1618418
Log:
QPID-6000 : Tidy up remove unused static, and use utility gzip mechanism

Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java?rev=1618418&r1=1618417&r2=1618418&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
Sat Aug 16 21:53:39 2014
@@ -58,9 +58,6 @@ import org.apache.qpid.util.Strings;
 public class BasicMessageProducer_0_10 extends BasicMessageProducer
 {
 
-    // TODO - move and add properties to change this
-    private static final int MESSAGE_COMPRESSION_THRESHOLD_SIZE = 4096;
-
     private static final Logger _logger = LoggerFactory.getLogger(BasicMessageProducer_0_10.class);
     private byte[] userIDBytes;
 
@@ -211,8 +208,11 @@ public class BasicMessageProducer_0_10 e
 
         ByteBuffer data = message.getData();
 
-        if(data.remaining() > getConnection().getMessageCompressionThresholdSize() &&
getConnection().getDelegate().isMessageCompressionSupported()
-           && getConnection().isMessageCompressionDesired() && messageProps.getContentEncoding()
== null)
+        if(data != null
+           && data.remaining() > getConnection().getMessageCompressionThresholdSize()
+           && getConnection().getDelegate().isMessageCompressionSupported()
+           && getConnection().isMessageCompressionDesired()
+           && messageProps.getContentEncoding() == null)
         {
             byte[] compressed = GZIPUtils.compressBufferToArray(data);
             if(compressed != null)

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java?rev=1618418&r1=1618417&r2=1618418&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
Sat Aug 16 21:53:39 2014
@@ -20,11 +20,8 @@
  */
 package org.apache.qpid.client;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.UUID;
-import java.util.zip.GZIPOutputStream;
 
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -47,6 +44,7 @@ import org.apache.qpid.framing.ContentBo
 import org.apache.qpid.framing.ContentHeaderBody;
 import org.apache.qpid.framing.ExchangeDeclareBody;
 import org.apache.qpid.framing.MethodRegistry;
+import org.apache.qpid.util.GZIPUtils;
 
 public class BasicMessageProducer_0_8 extends BasicMessageProducer
 {
@@ -152,34 +150,17 @@ public class BasicMessageProducer_0_8 ex
 
         int size = (payload != null) ? payload.remaining() : 0;
 
-        if(size > getConnection().getMessageCompressionThresholdSize() && getConnection().getDelegate().isMessageCompressionSupported()
-                && getConnection().isMessageCompressionDesired() && contentHeaderProperties.getEncoding()
== null)
+        byte[] compressed;
+        if(size > getConnection().getMessageCompressionThresholdSize()
+               && getConnection().getDelegate().isMessageCompressionSupported()
+               && getConnection().isMessageCompressionDesired()
+               && contentHeaderProperties.getEncoding() == null
+               && (compressed = GZIPUtils.compressBufferToArray(payload)) != null)
         {
             contentHeaderProperties.setEncoding("gzip");
-            try(ByteArrayOutputStream compressedOutputBuffer = new ByteArrayOutputStream(size
/ 2))
-            {
-                try (GZIPOutputStream output = new GZIPOutputStream(compressedOutputBuffer))
-                {
-                    if(payload.hasArray())
-                    {
-                        output.write(payload.array(),payload.position()+payload.arrayOffset(),payload.remaining());
-                    }
-                    else
-                    {
-                        byte[] tmp = new byte[size];
-                        payload.get(tmp);
-                        output.write(tmp);
-                    }
-                }
+            payload = ByteBuffer.wrap(compressed);
+            size = compressed.length;
 
-                byte[] compressedData = compressedOutputBuffer.toByteArray();
-                payload = ByteBuffer.wrap(compressedData);
-                size = compressedData.length;
-            }
-            catch (IOException e)
-            {
-                // TODO - shouldn't happen
-            }
         }
         final int contentBodyFrameCount = calculateContentBodyFrameCount(payload);
         final AMQFrame[] frames = new AMQFrame[2 + contentBodyFrameCount];



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message