You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2008/08/05 21:33:12 UTC

svn commit: r682887 [2/2] - in /incubator/qpid/trunk/qpid/java: client/example/src/main/java/org/apache/qpid/example/amqpexample/direct/ client/example/src/main/java/org/apache/qpid/example/amqpexample/fanout/ client/example/src/main/java/org/apache/qp...

Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java?rev=682887&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java Tue Aug  5 12:33:11 2008
@@ -0,0 +1,82 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.util;
+
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * Strings
+ *
+ */
+
+public final class Strings
+{
+
+    private static final byte[] EMPTY = new byte[0];
+
+    private static final ThreadLocal<char[]> charbuf = new ThreadLocal()
+    {
+        public char[] initialValue()
+        {
+            return new char[4096];
+        }
+    };
+
+    public static final byte[] toUTF8(String str)
+    {
+        if (str == null)
+        {
+            return EMPTY;
+        }
+        else
+        {
+            final int size = str.length();
+            char[] chars = charbuf.get();
+            if (size > chars.length)
+            {
+                chars = new char[Math.max(size, 2*chars.length)];
+                charbuf.set(chars);
+            }
+
+            str.getChars(0, size, chars, 0);
+            final byte[] bytes = new byte[size];
+            for (int i = 0; i < size; i++)
+            {
+                if (chars[i] > 127)
+                {
+                    try
+                    {
+                        return str.getBytes("UTF-8");
+                    }
+                    catch (UnsupportedEncodingException e)
+                    {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                bytes[i] = (byte) chars[i];
+            }
+            return bytes;
+        }
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/qpid/trunk/qpid/java/tools/bin/qpid-bench
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/tools/bin/qpid-bench?rev=682887&r1=682886&r2=682887&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/tools/bin/qpid-bench (original)
+++ incubator/qpid/trunk/qpid/java/tools/bin/qpid-bench Tue Aug  5 12:33:11 2008
@@ -30,7 +30,6 @@
 export JAVA=java \
        JAVA_VM=-server \
        JAVA_MEM=-Xmx1024m \
-       JAVA_GC="-XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError" \
        QPID_CLASSPATH=$QPID_LIBS
 
 . qpid-run org.apache.qpid.tools.QpidBench "$@"

Modified: incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java?rev=682887&r1=682886&r2=682887&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java (original)
+++ incubator/qpid/trunk/qpid/java/tools/src/main/java/org/apache/qpid/tools/QpidBench.java Tue Aug  5 12:33:11 2008
@@ -524,7 +524,7 @@
         StringBuilder str = new StringBuilder();
         for (int i = 0; i < opts.size; i++)
         {
-            str.append((char) i);
+            str.append((char) (i % 128));
         }
 
         String body = str.toString();
@@ -782,10 +782,8 @@
                 dp.setTimestamp(System.currentTimeMillis());
             }
 
-            ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED);
-            ssn.header(dp, mp);
-            ssn.data(body.slice());
-            ssn.endData();
+            ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
+                                new Header(dp, mp), body.slice());
             count++;
         }
 
@@ -827,10 +825,9 @@
                      {
                          ssn.messageTransfer("amq.direct",
                                              MessageAcceptMode.NONE,
-                                             MessageAcquireMode.PRE_ACQUIRED);
-                         ssn.header(dp, mp);
-                         ssn.data(echo);
-                         ssn.endData();
+                                             MessageAcquireMode.PRE_ACQUIRED,
+                                             new Header(dp, mp),
+                                             echo);
                      }
 
                      if (sample)