Package org.apache.calcite.util
Class BitString
- java.lang.Object
-
- org.apache.calcite.util.BitString
-
public class BitString extends java.lang.Object
String of bits.A bit string logically consists of a set of '0' and '1' values, of a specified length. The length is preserved even if this means that the bit string has leading '0's.
You can create a bit string from a string of 0s and 1s (
BitString(String, int)
orcreateFromBitString(java.lang.String)
), or from a string of hex digits (createFromHexString(java.lang.String)
). You can convert it to a byte array (getAsByteArray()
), to a bit string (toBitString()
), or to a hex string (toHexString()
). A utility methodtoByteArrayFromBitString(java.lang.String, int)
converts a bit string directly to a byte array.This class is immutable: once created, none of the methods modify the value.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BitString(java.lang.String bits, int bitCount)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BitString
concat(java.util.List<BitString> args)
Concatenates some BitStrings.static BitString
createFromBitString(java.lang.String s)
Creates a BitString representation out of a Bit String.static BitString
createFromBytes(byte[] bytes)
Creates a BitString from an array of bytes.static BitString
createFromHexString(java.lang.String s)
Creates a BitString representation out of a Hex String.byte[]
getAsByteArray()
int
getBitCount()
java.lang.String
toBitString()
Returns this bit string as a bit string, such as "10110".static byte[]
toByteArrayFromBitString(java.lang.String bits, int bitCount)
Converts a bit string to an array of bytes.java.lang.String
toHexString()
Converts this bit string to a hex string, such as "7AB".java.lang.String
toString()
-
-
-
Method Detail
-
createFromHexString
public static BitString createFromHexString(java.lang.String s)
Creates a BitString representation out of a Hex String. Initial zeros are be preserved. Hex String is defined in the SQL standard to be a string with odd number of hex digits. An even number of hex digits is in the standard a Binary String.- Parameters:
s
- a string, in hex notation- Throws:
java.lang.NumberFormatException
- ifs
is invalid.
-
createFromBitString
public static BitString createFromBitString(java.lang.String s)
Creates a BitString representation out of a Bit String. Initial zeros are be preserved.- Parameters:
s
- a string of 0s and 1s.- Throws:
java.lang.NumberFormatException
- ifs
is invalid.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getBitCount
public int getBitCount()
-
getAsByteArray
public byte[] getAsByteArray()
-
toBitString
public java.lang.String toBitString()
Returns this bit string as a bit string, such as "10110".
-
toHexString
public java.lang.String toHexString()
Converts this bit string to a hex string, such as "7AB".
-
toByteArrayFromBitString
public static byte[] toByteArrayFromBitString(java.lang.String bits, int bitCount)
Converts a bit string to an array of bytes.
-
concat
public static BitString concat(java.util.List<BitString> args)
Concatenates some BitStrings. Concatenates all at once, not pairwise, to avoid string copies.- Parameters:
args
- BitString[]
-
createFromBytes
public static BitString createFromBytes(byte[] bytes)
Creates a BitString from an array of bytes.- Parameters:
bytes
- Bytes- Returns:
- BitString
-
-