org.apache.derbyTesting.unitTests.util
Class BitUtil

java.lang.Object
  extended by org.apache.derbyTesting.unitTests.util.BitUtil

public class BitUtil
extends java.lang.Object

This class provides utility methods for converting byte arrays to hexidecimal Strings and manipulating BIT/BIT VARYING values as a packed vector of booleans.

The BIT/BIT VARYING methods are modeled after some methods in the java.util.BitSet class. An alternative to using a SQL BIT (VARYING) column in conjunction with the methods provided herein to provide bit manipulation would be to use a serialized java.util.BitSet column instead.

This class contains the following static methods:

Since these methods effectively allow a SQL BIT to be considered as an array of booleans, all offsets (position parameters) are zero based. So if you want to set the first bit of a BIT type, you would use set(MyBitColumn, 0) .

Examples:


Field Summary
private static char[] hex_table
           
 
Constructor Summary
BitUtil()
           
 
Method Summary
static byte[] clear(byte[] bytes, int position)
          Clear the bit at the specified position
static boolean get(byte[] bytes, int position)
          Check to see if the specified bit is set
static java.lang.String hexDump(byte[] data)
          Convert a byte array to a human-readable String for debugging purposes.
static byte[] set(byte[] bytes, int position)
          Set the bit at the specified position
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hex_table

private static char[] hex_table
Constructor Detail

BitUtil

public BitUtil()
Method Detail

set

public static byte[] set(byte[] bytes,
                         int position)
Set the bit at the specified position

Parameters:
bytes - the byte array
position - the bit to set, starting from zero
Returns:
the byte array with the set bit
Throws:
java.lang.IndexOutOfBoundsException - on bad position

clear

public static byte[] clear(byte[] bytes,
                           int position)
Clear the bit at the specified position

Parameters:
bytes - the byte array
position - the bit to clear, starting from zero
Returns:
the byte array with the cleared bit
Throws:
java.lang.IndexOutOfBoundsException - on bad position

get

public static boolean get(byte[] bytes,
                          int position)
Check to see if the specified bit is set

Parameters:
bytes - the byte array
position - the bit to check, starting from zero
Returns:
true/false
Throws:
java.lang.IndexOutOfBoundsException - on bad position

hexDump

public static java.lang.String hexDump(byte[] data)
Convert a byte array to a human-readable String for debugging purposes.


Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.