org.apache.cassandra.utils
Class ByteBufferUtil

java.lang.Object
  extended by org.apache.cassandra.utils.ByteBufferUtil

public class ByteBufferUtil
extends java.lang.Object

Utility methods to make ByteBuffers less painful The following should illustrate the different ways byte buffers can be used public void testArrayOffet() { byte[] b = "test_slice_array".getBytes(); ByteBuffer bb = ByteBuffer.allocate(1024); assert bb.position() == 0; assert bb.limit() == 1024; assert bb.capacity() == 1024; bb.put(b); assert bb.position() == b.length; assert bb.remaining() == bb.limit() - bb.position(); ByteBuffer bb2 = bb.slice(); assert bb2.position() == 0; //slice should begin at other buffers current position assert bb2.arrayOffset() == bb.position(); //to match the position in the underlying array one needs to //track arrayOffset assert bb2.limit()+bb2.arrayOffset() == bb.limit(); assert bb2.remaining() == bb.remaining(); } }


Constructor Summary
ByteBufferUtil()
           
 
Method Summary
static java.nio.ByteBuffer bytes(java.lang.String s)
           
static java.nio.ByteBuffer clone(java.nio.ByteBuffer o)
           
static int compare(byte[] o1, java.nio.ByteBuffer o2)
           
static int compare(java.nio.ByteBuffer o1, byte[] o2)
           
static int compareUnsigned(java.nio.ByteBuffer o1, java.nio.ByteBuffer o2)
           
static java.lang.String string(java.nio.ByteBuffer b)
           
static java.lang.String string(java.nio.ByteBuffer b, java.nio.charset.Charset charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferUtil

public ByteBufferUtil()
Method Detail

compareUnsigned

public static int compareUnsigned(java.nio.ByteBuffer o1,
                                  java.nio.ByteBuffer o2)

compare

public static int compare(byte[] o1,
                          java.nio.ByteBuffer o2)

compare

public static int compare(java.nio.ByteBuffer o1,
                          byte[] o2)

string

public static java.lang.String string(java.nio.ByteBuffer b,
                                      java.nio.charset.Charset charset)

string

public static java.lang.String string(java.nio.ByteBuffer b)

bytes

public static java.nio.ByteBuffer bytes(java.lang.String s)

clone

public static java.nio.ByteBuffer clone(java.nio.ByteBuffer o)


Copyright © 2011 The Apache Software Foundation