activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r469986 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data: StoreByteArrayInputStream.java StoreByteArrayOutputStream.java
Date Wed, 01 Nov 2006 17:13:39 GMT
Author: rajdavies
Date: Wed Nov  1 09:13:39 2006
New Revision: 469986

URL: http://svn.apache.org/viewvc?view=rev&rev=469986
Log:
support for ByteSequence

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayInputStream.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayOutputStream.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayInputStream.java?view=diff&rev=469986&r1=469985&r2=469986
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayInputStream.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayInputStream.java
Wed Nov  1 09:13:39 2006
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UTFDataFormatException;
+import org.apache.activemq.util.ByteSequence;
 /**
  * Optimized ByteArrayInputStream that can be used more than once
  * 
@@ -29,15 +30,27 @@
 public final class StoreByteArrayInputStream extends InputStream implements DataInput{
     private byte[] buf;
     private int pos;
+    private int offset;
 
     /**
-     * Creates a <code>WireByteArrayInputStream</code>.
+     * Creates a <code>StoreByteArrayInputStream</code>.
      * 
      * @param buf the input buffer.
      */
     public StoreByteArrayInputStream(byte buf[]){
         this.buf=buf;
         this.pos=0;
+        this.offset = 0;
+    }
+    
+    /**
+     * Creates a <code>StoreByteArrayInputStream</code>.
+     * 
+     * @param sequence the input buffer.
+     */
+    public StoreByteArrayInputStream(ByteSequence sequence){
+        this.buf=sequence.getData();
+        this.offset=this.pos=sequence.getOffset();
     }
 
     /**
@@ -47,8 +60,12 @@
         this(new byte[0]);
     }
 
+    /**
+     * 
+     * @return the size
+     */
     public int size(){
-        return pos;
+        return pos-offset;
     }
 
     /**
@@ -59,13 +76,23 @@
     }
 
     /**
-     * reset the <code>WireByteArrayInputStream</code> to use an new byte array
+     * reset the <code>StoreByteArrayInputStream</code> to use an new byte array
      * 
      * @param newBuff
      */
     public void restart(byte[] newBuff){
         buf=newBuff;
         pos=0;
+    }
+    
+    /**
+     * reset the <code>StoreByteArrayInputStream</code> to use an new ByteSequence
+     * @param sequence 
+     *  
+     */
+    public void restart(ByteSequence sequence){
+        this.buf=sequence.getData();
+        this.pos=sequence.getOffset();
     }
 
     /**

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayOutputStream.java?view=diff&rev=469986&r1=469985&r2=469986
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayOutputStream.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/StoreByteArrayOutputStream.java
Wed Nov  1 09:13:39 2006
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UTFDataFormatException;
+import org.apache.activemq.util.ByteSequence;
 /**
  * Optimized ByteArrayOutputStream
  * 
@@ -59,6 +60,14 @@
         buf=new byte[size];
         pos=0;
     }
+    
+    /**
+     * Get a ByteSequence from the stream
+     * @return the byte sequence
+     */
+    public ByteSequence toByteSequence() {
+        return new ByteSequence(buf, 0, pos);
+    }
 
     /**
      * Writes the specified byte to this byte array output stream.
@@ -117,6 +126,8 @@
     public int size(){
         return pos;
     }
+    
+    
 
     public void writeBoolean(boolean v){
         ensureEnoughBuffer(1);



Mime
View raw message