Package herddb.utils
Class Bytes
- java.lang.Object
-
- herddb.utils.Bytes
-
- All Implemented Interfaces:
SizeAwareObject,Comparable<Bytes>
public final class Bytes extends Object implements Comparable<Bytes>, SizeAwareObject
A wrapper for byte[], in order to use it as keys on HashMaps- Author:
- enrico.olivelli
-
-
Field Summary
Fields Modifier and Type Field Description Objectdeserializedstatic BytesEMPTY_ARRAYstatic BytesPOSITIVE_INFINITY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Stringarraytohexstring(byte[] buffer, int offset, int length)static byte[]booleanToByteArray(boolean value)static intcompare(byte[] left, byte[] right)static intcompareInt(byte[] array, int index, int value)static intcompareInt(byte[] array, int index, long value)static intcompareLong(byte[] array, int index, int value)static intcompareLong(byte[] array, int index, long value)intcompareTo(Bytes o)static byte[]doubleToByteArray(double value)booleanequals(Object obj)static longestimateSize(byte[] value)static Bytesfrom_array(byte[] data)static Bytesfrom_array(byte[] data, int offset, int len)static Bytesfrom_boolean(boolean value)static Bytesfrom_double(double value)static Bytesfrom_float_array(float[] floatArray)static Bytesfrom_int(int value)static Bytesfrom_long(long value)static Bytesfrom_nullable_array(byte[] data)static Bytesfrom_string(String s)static Bytesfrom_timestamp(Timestamp value)byte[]getBuffer()longgetEstimatedSize()Returns an estimation of the heap size of this instance.intgetLength()intgetOffset()inthashCode()static byte[]intToByteArray(int value)booleanisShared()static byte[]longToByteArray(long value)ByteArrayCursornewCursor()Bytesnext()Returns the nextBytesinstance.BytesnonShared()Ensure that this value is not retaining strong references to a shared bufferstatic voidputBoolean(byte[] bytes, int offset, boolean val)static voidputDouble(byte[] bytes, int offset, double val)static voidputInt(byte[] array, int index, int value)static voidputLong(byte[] array, int index, long value)static booleanstartsWith(byte[] left, int offset, int bufferlen, int max, byte[] right)booleanstartsWith(int length, byte[] prefix)static byte[]string_to_array(String s)static byte[]timestampToByteArray(Timestamp value)byte[]to_array()booleanto_boolean()doubleto_double()float[]to_float_array()static float[]to_float_array(byte[] buffer, int offset, int length)intto_int()longto_long()static RawStringto_rawstring(byte[] data)RawStringto_RawString()Stringto_string()static Stringto_string(byte[] data)Timestampto_timestamp()static booleantoBoolean(byte[] bytes, int offset)static doubletoDouble(byte[] bytes, int offset)static inttoInt(byte[] array, int index)static longtoLong(byte[] array, int index)StringtoString()static TimestamptoTimestamp(byte[] bytes, int offset)
-
-
-
Method Detail
-
estimateSize
public static long estimateSize(byte[] value)
-
getEstimatedSize
public long getEstimatedSize()
Description copied from interface:SizeAwareObjectReturns an estimation of the heap size of this instance.- Specified by:
getEstimatedSizein interfaceSizeAwareObject- Returns:
- size estimation in bytes
-
string_to_array
public static byte[] string_to_array(String s)
-
longToByteArray
public static byte[] longToByteArray(long value)
-
intToByteArray
public static byte[] intToByteArray(int value)
-
doubleToByteArray
public static byte[] doubleToByteArray(double value)
-
timestampToByteArray
public static byte[] timestampToByteArray(Timestamp value)
-
booleanToByteArray
public static byte[] booleanToByteArray(boolean value)
-
from_long
public static Bytes from_long(long value)
-
from_array
public static Bytes from_array(byte[] data)
-
from_array
public static Bytes from_array(byte[] data, int offset, int len)
-
from_nullable_array
public static Bytes from_nullable_array(byte[] data)
-
to_array
public byte[] to_array()
-
to_float_array
public float[] to_float_array()
-
to_float_array
public static float[] to_float_array(byte[] buffer, int offset, int length)
-
from_float_array
public static Bytes from_float_array(float[] floatArray)
-
from_int
public static Bytes from_int(int value)
-
from_boolean
public static Bytes from_boolean(boolean value)
-
from_double
public static Bytes from_double(double value)
-
to_long
public long to_long()
-
to_RawString
public RawString to_RawString()
-
to_int
public int to_int()
-
to_string
public String to_string()
-
to_string
public static String to_string(byte[] data)
-
to_rawstring
public static RawString to_rawstring(byte[] data)
-
to_timestamp
public Timestamp to_timestamp()
-
to_boolean
public boolean to_boolean()
-
to_double
public double to_double()
-
putLong
public static void putLong(byte[] array, int index, long value)
-
putInt
public static void putInt(byte[] array, int index, int value)
-
putBoolean
public static void putBoolean(byte[] bytes, int offset, boolean val)
-
putDouble
public static void putDouble(byte[] bytes, int offset, double val)
-
toLong
public static long toLong(byte[] array, int index)
-
compareInt
public static int compareInt(byte[] array, int index, int value)
-
compareInt
public static int compareInt(byte[] array, int index, long value)
-
compareLong
public static int compareLong(byte[] array, int index, int value)
-
compareLong
public static int compareLong(byte[] array, int index, long value)
-
toInt
public static int toInt(byte[] array, int index)
-
toTimestamp
public static Timestamp toTimestamp(byte[] bytes, int offset)
-
toBoolean
public static boolean toBoolean(byte[] bytes, int offset)
-
toDouble
public static double toDouble(byte[] bytes, int offset)
-
compare
public static int compare(byte[] left, byte[] right)
-
compareTo
public int compareTo(Bytes o)
- Specified by:
compareToin interfaceComparable<Bytes>
-
startsWith
public static boolean startsWith(byte[] left, int offset, int bufferlen, int max, byte[] right)
-
getLength
public int getLength()
-
getBuffer
public byte[] getBuffer()
-
getOffset
public int getOffset()
-
arraytohexstring
public static String arraytohexstring(byte[] buffer, int offset, int length)
-
newCursor
public ByteArrayCursor newCursor()
-
next
public Bytes next()
Returns the nextBytesinstance.Depending on current instance it couldn't be possible to evaluate the next one: if every bit in current byte array is already 1 next would generate an overflow and isn't permitted.
- Returns:
- the next Bytes instance
- Throws:
IllegalStateException- if cannot evaluate a next value.
-
startsWith
public boolean startsWith(int length, byte[] prefix)
-
nonShared
public Bytes nonShared()
Ensure that this value is not retaining strong references to a shared buffer- Returns:
- the buffer itself or a copy
-
isShared
public boolean isShared()
-
-