uk.co.silentsoftware.core.helpers
Class ByteHelper

java.lang.Object
  extended by uk.co.silentsoftware.core.helpers.ByteHelper

public final class ByteHelper
extends java.lang.Object

Byte and BitSet manipulation and conversion class Disclaimer: I understand bytes and bits, but my manipulation of them is shockingly bad so I wrote this class to help me with the high level Java objects.


Constructor Summary
private ByteHelper()
          Private constructor since we want static use only
 
Method Summary
static byte[] bitSetToBytes(java.util.BitSet bs)
          Copy a BitSet to a byte array
static java.util.BitSet copyBits(java.util.BitSet source, java.util.BitSet dest, int fromIndex)
          Copy bits completely from a source BitSet to a destination BitSet starting at the destination index
static byte[] copyBytes(byte[] from, byte[] to, int fromIndex)
          Copy bytes completely from a source byte array to a destination byte array starting at the destination index
static byte getChecksum(byte[] result)
          Implementation of an XOR checksum
static void put(java.nio.ByteBuffer bb, byte[] bytes, int from)
          The missing method on a ByteBuffer - allows copying of multiple bytes into the buffer.
static java.util.BitSet reverseBitSet(java.util.BitSet bs)
          Noddy method to reverse a BitSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteHelper

private ByteHelper()
Private constructor since we want static use only

Method Detail

reverseBitSet

public static java.util.BitSet reverseBitSet(java.util.BitSet bs)
Noddy method to reverse a BitSet. Basically this is just to fix the endianness of the image bytes.

Parameters:
bs -
Returns:

bitSetToBytes

public static byte[] bitSetToBytes(java.util.BitSet bs)
Copy a BitSet to a byte array

Parameters:
bs -
Returns:

copyBits

public static java.util.BitSet copyBits(java.util.BitSet source,
                                        java.util.BitSet dest,
                                        int fromIndex)
Copy bits completely from a source BitSet to a destination BitSet starting at the destination index

Parameters:
source -
dest -
fromIndex -
Returns:

copyBytes

public static byte[] copyBytes(byte[] from,
                               byte[] to,
                               int fromIndex)
Copy bytes completely from a source byte array to a destination byte array starting at the destination index

Parameters:
from -
to -
fromIndex -
Returns:
the copied byte array

put

public static void put(java.nio.ByteBuffer bb,
                       byte[] bytes,
                       int from)
The missing method on a ByteBuffer - allows copying of multiple bytes into the buffer.

Parameters:
bb -
bytes -
from -

getChecksum

public static byte getChecksum(byte[] result)
Implementation of an XOR checksum

Parameters:
result -
Returns: