You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/10/29 10:00:19 UTC

svn commit: r830864 - in /activemq/sandbox/activemq-apollo: activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/ activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/ activemq-protobuf/activemq-protobuf/src/main/j...

Author: chirino
Date: Thu Oct 29 09:00:18 2009
New Revision: 830864

URL: http://svn.apache.org/viewvc?rev=830864&view=rev
Log:
More buffer tweaks.. making more methods final.


Modified:
    activemq/sandbox/activemq-apollo/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/PathSupport.java
    activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/TestUtil.java
    activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java
    activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
    activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TextFormat.java
    activemq/sandbox/activemq-apollo/activemq-store/src/test/java/org/apache/activemq/broker/store/StoreTestBase.java
    activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/AsciiBuffer.java
    activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java
    activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/UTF8Buffer.java

Modified: activemq/sandbox/activemq-apollo/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/PathSupport.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/PathSupport.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/PathSupport.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/path/PathSupport.java Thu Oct 29 09:00:18 2009
@@ -39,11 +39,11 @@
         while (true) {
             int idx = subject.indexOf(SEPARATOR, previous);
             if (idx < 0) {
-            	AsciiBuffer buffer = subject.slice(previous, lastIndex + 1);
+            	AsciiBuffer buffer = subject.slice(previous, lastIndex + 1).ascii();
                 list.add(buffer);
                 break;
             }
-        	AsciiBuffer buffer = subject.slice(previous, idx);
+        	AsciiBuffer buffer = subject.slice(previous, idx).ascii();
             list.add(buffer);
             previous = idx + 1;
         }

Modified: activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/TestUtil.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/TestUtil.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/TestUtil.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/TestUtil.java Thu Oct 29 09:00:18 2009
@@ -729,7 +729,7 @@
    * {@link com.google.testing.util.TestUtil#getDefaultSrcDir}.
    */
   public static String readTextFromFile(String filePath) {
-    return readBytesFromFile(filePath).toStringUtf8();
+    return readBytesFromFile(filePath).utf8().toString();
   }
 
   private static File getTestDataDir() {

Modified: activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java Thu Oct 29 09:00:18 2009
@@ -1954,7 +1954,7 @@
             if( field.isStringType() ) {
                 return asJavaString(defaultOption.getValue());
             } else if( field.getType() == FieldDescriptor.BYTES_TYPE ) {
-                return "new "+javaType(field)+"("+asJavaString(defaultOption.getValue())+")";
+                return "new "+javaType(field)+"(org.apache.activemq.util.buffer.UTF8Buffer.encode("+asJavaString(defaultOption.getValue())+"))";
             } else if( field.isInteger32Type() ) {
                 int v;
                 if( field.getType() == FieldDescriptor.UINT32_TYPE ) {

Modified: activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java Thu Oct 29 09:00:18 2009
@@ -16,13 +16,6 @@
  */
 package org.apache.activemq.protobuf.compiler;
 
-import static org.apache.activemq.protobuf.WireFormat.WIRETYPE_FIXED32;
-import static org.apache.activemq.protobuf.WireFormat.WIRETYPE_FIXED64;
-import static org.apache.activemq.protobuf.WireFormat.WIRETYPE_LENGTH_DELIMITED;
-import static org.apache.activemq.protobuf.WireFormat.WIRETYPE_START_GROUP;
-import static org.apache.activemq.protobuf.WireFormat.WIRETYPE_VARINT;
-import static org.apache.activemq.protobuf.WireFormat.makeTag;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -36,7 +29,8 @@
 
 import org.apache.activemq.protobuf.compiler.parser.ParseException;
 import org.apache.activemq.protobuf.compiler.parser.ProtoParser;
-import org.apache.activemq.util.buffer.Buffer;
+
+import static org.apache.activemq.protobuf.WireFormat.*;
 
 public class JavaGenerator {
 
@@ -1343,7 +1337,7 @@
             if( field.isStringType() ) {
                 return asJavaString(defaultOption.getValue());
             } else if( field.getType() == FieldDescriptor.BYTES_TYPE ) {
-                return "new org.apache.activemq.util.buffer.Buffer("+asJavaString(defaultOption.getValue())+")";
+                return "new org.apache.activemq.util.buffer.Buffer(org.apache.activemq.util.buffer.UTF8Buffer.encode("+asJavaString(defaultOption.getValue())+"))";
             } else if( field.isInteger32Type() ) {
                 int v;
                 if( field.getType() == FieldDescriptor.UINT32_TYPE ) {

Modified: activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TextFormat.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TextFormat.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TextFormat.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TextFormat.java Thu Oct 29 09:00:18 2009
@@ -481,7 +481,7 @@
   static String escapeBytes(Buffer input) {
     StringBuilder builder = new StringBuilder(input.getLength());
     for (int i = 0; i < input.getLength(); i++) {
-      byte b = input.byteAt(i);
+      byte b = input.get(i);
       switch (b) {
         // Java does not recognize \a or \v, apparently.
         case 0x07: builder.append("\\a" ); break;

Modified: activemq/sandbox/activemq-apollo/activemq-store/src/test/java/org/apache/activemq/broker/store/StoreTestBase.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-store/src/test/java/org/apache/activemq/broker/store/StoreTestBase.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-store/src/test/java/org/apache/activemq/broker/store/StoreTestBase.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-store/src/test/java/org/apache/activemq/broker/store/StoreTestBase.java Thu Oct 29 09:00:18 2009
@@ -60,7 +60,7 @@
 
     public void testMessageAdd() throws Exception {
         final MessageRecord expected = new MessageRecord();
-        expected.setBuffer(new Buffer("buffer"));
+        expected.setBuffer(new AsciiBuffer("buffer").buffer());
         expected.setEncoding(new AsciiBuffer("encoding"));
         expected.setMessageId(new AsciiBuffer("1000"));
         expected.setKey(store.allocateStoreTracking());
@@ -113,7 +113,7 @@
         queue.setApplicationType((short) 1);
 
         final MessageRecord message = new MessageRecord();
-        message.setBuffer(new Buffer("buffer"));
+        message.setBuffer(new AsciiBuffer("buffer").buffer());
         message.setEncoding(new AsciiBuffer("encoding"));
         message.setMessageId(new AsciiBuffer("1000"));
         message.setKey(store.allocateStoreTracking());
@@ -261,7 +261,7 @@
         store.execute(new VoidCallback<Exception>() {
             @Override
             public void run(Session session) throws Exception {
-                AsciiBuffer overwrite = new AsciiBuffer("overwrite");
+//                AsciiBuffer overwrite = new AsciiBuffer("overwrite");
                 session.mapRemove(map);
                 Iterator<AsciiBuffer> r = session.mapList(null, 10);
                 assertEquals("Not expecting any maps", false, r.hasNext());

Modified: activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/AsciiBuffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/AsciiBuffer.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/AsciiBuffer.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/AsciiBuffer.java Thu Oct 29 09:00:18 2009
@@ -1,9 +1,24 @@
+/**
+ * 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.activemq.util.buffer;
 
-
-
-
-
+/**
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
 final public class AsciiBuffer extends Buffer {
 
     private int hashCode;
@@ -26,34 +41,9 @@
         this.value = value;
     }
 
-    public static AsciiBuffer ascii(String value) {
-        if( value==null ) {
-            return null;
-        }
-        return new AsciiBuffer(value);
-    }
-    
-    public static AsciiBuffer ascii(Buffer buffer) {
-        if( buffer==null ) {
-            return null;
-        }
-        if( buffer.getClass() == AsciiBuffer.class ) {
-            return (AsciiBuffer) buffer;
-        }
-        return new AsciiBuffer(buffer);
-    }    
-    
-    public AsciiBuffer compact() {
-        if (length != data.length) {
-            return new AsciiBuffer(toByteArray());
-        }
-        return this;
-    }
-
-    @Override
-    protected AsciiBuffer createBuffer(byte[] data, int offset, int length) {
-		return new AsciiBuffer(data, offset, length);
-	}
+    ///////////////////////////////////////////////////////////////////
+    // Overrides
+    ///////////////////////////////////////////////////////////////////
     
     public String toString()
     {
@@ -82,6 +72,27 @@
         return hashCode;
     }
     
+    ///////////////////////////////////////////////////////////////////
+    // Statics
+    ///////////////////////////////////////////////////////////////////
+
+    public static AsciiBuffer ascii(String value) {
+        if( value==null ) {
+            return null;
+        }
+        return new AsciiBuffer(value);
+    }
+    
+    public static AsciiBuffer ascii(Buffer buffer) {
+        if( buffer==null ) {
+            return null;
+        }
+        if( buffer.getClass() == AsciiBuffer.class ) {
+            return (AsciiBuffer) buffer;
+        }
+        return new AsciiBuffer(buffer);
+    }   
+    
     static public byte[] encode(String value)
     {
         int size = value.length();
@@ -91,12 +102,13 @@
         }
         return rc;
     }
+    
     static public String decode(Buffer value)
     {
         int size = value.getLength();
         char rc[] = new char[size];
         for( int i=0; i < size; i++ ) {
-            rc[i] = (char)(value.byteAt(i) & 0xFF );
+            rc[i] = (char)(value.get(i) & 0xFF );
         }
         return new String(rc);
     }

Modified: activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/Buffer.java Thu Oct 29 09:00:18 2009
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.activemq.util.buffer;
 
 import java.util.ArrayList;
@@ -33,13 +32,6 @@
         this(other.data, other.offset, other.length);
     }
 
-    public static String string(Buffer value) {
-        if( value==null ) {
-            return null;
-        }
-        return value.toString();
-    }
-
     public Buffer(int size) {
         this(new byte[size]);
     }
@@ -54,33 +46,20 @@
         this.length = length;
     }
 
-    @Deprecated
-    public Buffer(String value) {
-        this(UTF8Buffer.encode(value));
-    }
-
-    @SuppressWarnings("unchecked")
-	public final <T extends Buffer> T slice(int low, int high) {
+	public final Buffer slice(int low, int high) {
         int sz;
-
         if (high < 0) {
             sz = length + high;
         } else {
             sz = high - low;
         }
-
         if (sz < 0) {
             sz = 0;
         }
-
-        return (T) createBuffer(data, offset + low, sz);
+        return new Buffer(data, (offset + low), sz);
     }
 
-    protected Buffer createBuffer(byte[] data, int offset, int length) {
-		return new Buffer(data, offset, length);
-	}
-
-	public final byte[] getData() {
+    public final byte[] getData() {
         return data;
     }
 
@@ -96,13 +75,13 @@
         return offset;
     }
     
-    public Buffer deepCopy() {
+    final public Buffer deepCopy() {
         byte t[] = new byte[length];
         System.arraycopy(data, offset, t, 0, length);
         return new Buffer(t);
     }
 
-    public Buffer compact() {
+    final public Buffer compact() {
         if (length != data.length) {
             return new Buffer(toByteArray());
         }
@@ -119,35 +98,10 @@
         return data;
     }
 
-    public byte byteAt(int i) {
+    final public byte get(int i) {
         return data[offset + i];
     }
 
-
-    @Override
-    public int hashCode() {
-        byte[] data = this.data;
-        int offset = this.offset;
-        int length = this.length;
-
-        byte[] target = new byte[4];
-        for (int i = 0; i < length; i++) {
-            target[i % 4] ^= data[offset + i];
-        }
-        return target[0] << 24 | target[1] << 16 | target[2] << 8 | target[3];
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this)
-            return true;
-
-        if (obj == null || obj.getClass() != Buffer.class)
-            return false;
-
-        return equals((Buffer) obj);
-    }
-
     final public boolean equals(Buffer obj) {
         byte[] data = this.data;
         int offset = this.offset;
@@ -208,6 +162,7 @@
     final public int indexOf(Buffer needle) {
         return indexOf(needle, 0);
     }
+    
     final public int indexOf(Buffer needle, int pos) {
         int max = length - needle.length;
         for (int i = pos; i < max; i++) {
@@ -240,28 +195,95 @@
         return true;
     }
 
-    final public static Buffer join(List<Buffer> items, Buffer seperator) {
-        if (items.isEmpty())
-            return new Buffer(seperator.data, 0, 0);
+    
+    final public Buffer trim() {
+        return trimFront().trimEnd();
+    }
 
-        int size = 0;
-        for (Buffer item : items) {
-            size += item.length;
+    final public Buffer trimEnd() {
+        byte data[] = this.data;
+        int offset = this.offset;
+        int length = this.length;
+        int end = offset+this.length-1;
+        int pos = end;
+        
+        while ((offset <= pos) && (data[pos] <= ' ')) {
+            pos--;
         }
-        size += seperator.length * (items.size() - 1);
+        return (pos == end) ? this : new Buffer(data, offset, (length-(end-pos))); 
+    }
 
-        int pos = 0;
-        byte data[] = new byte[size];
-        for (Buffer item : items) {
-            if (pos != 0) {
-                System.arraycopy(seperator.data, seperator.offset, data, pos, seperator.length);
-                pos += seperator.length;
+    final public Buffer trimFront() {
+        byte data[] = this.data;
+        int offset = this.offset;
+        int end = offset+this.length;
+        int pos = offset;
+        while ((pos < end) && (data[pos] <= ' ')) {
+            pos++;
+        }
+        return (pos == offset) ? this : new Buffer(data, pos, (length-(pos-offset))); 
+    }
+
+    final public Buffer buffer() {
+        return new Buffer(this);
+    }
+    final public AsciiBuffer ascii() {
+        return new AsciiBuffer(this);
+    }
+    final public  UTF8Buffer utf8() {
+        return new UTF8Buffer(this);
+    }
+    
+    final public Buffer[] split(byte separator) {
+        ArrayList<Buffer> rc = new ArrayList<Buffer>();
+        
+        byte data[] = this.data;
+        int pos = this.offset;
+        int nextStart = pos;
+        int end = pos+this.length;
+
+        while( pos < end ) {
+            if( data[pos]==separator ) {
+                if( nextStart < pos ) {
+                    rc.add(new Buffer(data, nextStart, (pos-nextStart)));
+                }
+                nextStart = pos+1;
             }
-            System.arraycopy(item.data, item.offset, data, pos, item.length);
-            pos += item.length;
+            pos++;
+        }
+        if( nextStart < pos ) {
+            rc.add(new Buffer(data, nextStart, (pos-nextStart)));
         }
 
-        return new Buffer(data, 0, size);
+        return rc.toArray(new Buffer[rc.size()]);
+    }
+    
+    ///////////////////////////////////////////////////////////////////
+    // Overrides
+    ///////////////////////////////////////////////////////////////////
+    
+    @Override
+    public int hashCode() {
+        byte[] data = this.data;
+        int offset = this.offset;
+        int length = this.length;
+
+        byte[] target = new byte[4];
+        for (int i = 0; i < length; i++) {
+            target[i % 4] ^= data[offset + i];
+        }
+        return target[0] << 24 | target[1] << 16 | target[2] << 8 | target[3];
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this)
+            return true;
+
+        if (obj == null || obj.getClass() != Buffer.class)
+            return false;
+
+        return equals((Buffer) obj);
     }
 
     @Override
@@ -272,20 +294,15 @@
         }
         return "{ offset: "+offset+", length: "+length+", data: \""+str+"\" }";
     }
-    
-    @Deprecated
-    public String toStringUtf8() {
-        return UTF8Buffer.decode(this);
-    }
 
     public int compareTo(Buffer o) {
-    	if( this == o )
-    		return 0;
-    	
+        if( this == o )
+            return 0;
+        
         byte[] data = this.data;
         int offset = this.offset;
         int length = this.length;
-    	
+        
         int oLength = o.length;
         int oOffset = o.offset;
         byte[] oData = o.data;
@@ -315,69 +332,41 @@
         }
         return length - oLength;
     }
-
-    final public byte get(int i) {
-        return data[offset+i];
-    }
     
-    final public Buffer trim() {
-        return trimFront().trimEnd();
-    }
-
-    final public Buffer trimEnd() {
-        byte data[] = this.data;
-        int offset = this.offset;
-        int length = this.length;
-        int end = offset+this.length-1;
-        int pos = end;
-        
-        while ((offset <= pos) && (data[pos] <= ' ')) {
-            pos--;
+    ///////////////////////////////////////////////////////////////////
+    // Statics
+    ///////////////////////////////////////////////////////////////////
+    
+    public static String string(Buffer value) {
+        if( value==null ) {
+            return null;
         }
-        return (pos == end) ? this : createBuffer(data, offset, length-(end-pos)); 
+        return value.toString();
     }
 
-    final public Buffer trimFront() {
-        byte data[] = this.data;
-        int offset = this.offset;
-        int end = offset+this.length;
-        int pos = offset;
-        while ((pos < end) && (data[pos] <= ' ')) {
-            pos++;
-        }
-        return (pos == offset) ? this : createBuffer(data, pos, length-(pos-offset)); 
-    }
+    final public static Buffer join(List<Buffer> items, Buffer seperator) {
+        if (items.isEmpty())
+            return new Buffer(seperator.data, 0, 0);
 
-    
-    public AsciiBuffer ascii() {
-        return new AsciiBuffer(this);
-    }
-    public  UTF8Buffer utf8() {
-        return new UTF8Buffer(this);
-    }
-    
-    public Buffer[] split(byte separator) {
-        ArrayList<Buffer> rc = new ArrayList<Buffer>();
-        
-        byte data[] = this.data;
-        int pos = this.offset;
-        int nextStart = pos;
-        int end = pos+this.length;
+        int size = 0;
+        for (Buffer item : items) {
+            size += item.length;
+        }
+        size += seperator.length * (items.size() - 1);
 
-        while( pos < end ) {
-            if( data[pos]==separator ) {
-                if( nextStart < pos ) {
-                    rc.add(createBuffer(data, nextStart, pos-nextStart));
-                }
-                nextStart = pos+1;
+        int pos = 0;
+        byte data[] = new byte[size];
+        for (Buffer item : items) {
+            if (pos != 0) {
+                System.arraycopy(seperator.data, seperator.offset, data, pos, seperator.length);
+                pos += seperator.length;
             }
-            pos++;
-        }
-        if( nextStart < pos ) {
-            rc.add(createBuffer(data, nextStart, pos-nextStart));
+            System.arraycopy(item.data, item.offset, data, pos, item.length);
+            pos += item.length;
         }
 
-        return rc.toArray(new Buffer[rc.size()]);
+        return new Buffer(data, 0, size);
     }
+    
 
 }

Modified: activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/UTF8Buffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/UTF8Buffer.java?rev=830864&r1=830863&r2=830864&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/UTF8Buffer.java (original)
+++ activemq/sandbox/activemq-apollo/activemq-util/src/main/java/org/apache/activemq/util/buffer/UTF8Buffer.java Thu Oct 29 09:00:18 2009
@@ -1,9 +1,26 @@
+/**
+ * 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.activemq.util.buffer;
 
 import java.io.UnsupportedEncodingException;
 
-
-
+/**
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
 final public class UTF8Buffer extends Buffer {
 
     int hashCode;
@@ -25,35 +42,10 @@
         super(encode(input));
     }
 
-    public static UTF8Buffer utf8(String value) {
-        if( value==null ) {
-            return null;
-        }
-        return new UTF8Buffer(value);
-    }
-
-    public static UTF8Buffer utf8(Buffer buffer) {
-        if( buffer==null ) {
-            return null;
-        }
-        if( buffer.getClass() == UTF8Buffer.class ) {
-            return (UTF8Buffer) buffer;
-        }
-        return new UTF8Buffer(buffer);
-    }
-
-    public UTF8Buffer compact() {
-        if (length != data.length) {
-            return new UTF8Buffer(toByteArray());
-        }
-        return this;
-    }
+    ///////////////////////////////////////////////////////////////////
+    // Overrides
+    ///////////////////////////////////////////////////////////////////
     
-    @Override
-    protected UTF8Buffer createBuffer(byte[] data, int offset, int length) {
-		return new UTF8Buffer(data, offset, length);
-	}
-
     public String toString()
     {
         if( value==null ) {
@@ -86,6 +78,26 @@
         }
         return hashCode;
     }
+
+    ///////////////////////////////////////////////////////////////////
+    // Statics
+    ///////////////////////////////////////////////////////////////////
+    public static UTF8Buffer utf8(String value) {
+        if( value==null ) {
+            return null;
+        }
+        return new UTF8Buffer(value);
+    }
+
+    public static UTF8Buffer utf8(Buffer buffer) {
+        if( buffer==null ) {
+            return null;
+        }
+        if( buffer.getClass() == UTF8Buffer.class ) {
+            return (UTF8Buffer) buffer;
+        }
+        return new UTF8Buffer(buffer);
+    }
     
     static public byte[] encode(String value)
     {