Class SqlJetUtility
- java.lang.Object
-
- org.tmatesoft.sqljet.core.internal.SqlJetUtility
-
public final class SqlJetUtility extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static ISqlJetMemoryManager
memoryManager
static java.lang.String
SQLJET_PACKAGENAME
-
Constructor Summary
Constructors Constructor Description SqlJetUtility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
absolute(long i)
Returns absolute value of argumentstatic java.lang.Object[]
addArrays(java.lang.Object[] array1, java.lang.Object[] array2)
static byte[]
addZeroByteEnd(byte[] b)
static java.lang.Object
adjustNumberType(java.lang.Object value)
static java.lang.Object[]
adjustNumberTypes(java.lang.Object[] key)
static SqlJetScope
adjustScopeNumberTypes(SqlJetScope scope)
static ISqlJetMemoryPointer
allocatePtr(int size)
static ISqlJetMemoryPointer
allocatePtr(int size, SqlJetMemoryBufferType bufferType)
static double
atof(ISqlJetMemoryPointer z)
static java.lang.Long
atoi64(java.lang.String str)
static boolean
bitSetTest(java.util.BitSet bitSet, int index)
Check to see if the i-th bit is set.static java.lang.Object[]
copyArray(java.lang.Object[] array)
static java.lang.Long
doubleToInt64(java.lang.Double r)
static ISqlJetMemoryPointer
fromByteBuffer(java.nio.ByteBuffer b)
static ISqlJetMemoryPointer
fromString(java.lang.String s, SqlJetEncoding enc)
GetByteBuffer
fromString
.static short
fromUnsigned(int value)
static int
fromUnsigned(long value)
static byte
fromUnsigned(short value)
static int
get2byte(ISqlJetMemoryPointer x)
Read a two-byte big-endian integer values.static int
get2byte(ISqlJetMemoryPointer x, int off)
Read a two-byte big-endian integer values.static int
get4byte(ISqlJetMemoryPointer p)
Read a four-byte big-endian integer value.static int
get4byte(ISqlJetMemoryPointer p, int pos)
Read a four-byte big-endian integer value.static long
get4byteUnsigned(byte[] p)
Read a four-byte big-endian integer value.static long
get4byteUnsigned(byte[] p, int pos)
Read a four-byte big-endian integer value.static long
get4byteUnsigned(ISqlJetMemoryPointer p)
Read a four-byte big-endian integer value.static long
get4byteUnsigned(ISqlJetMemoryPointer p, int pos)
Read a four-byte big-endian integer value.static boolean
getBoolSysProp(java.lang.String propName, boolean defValue)
static byte[]
getBytes(java.lang.String string)
static <T extends java.lang.Enum<T>>
TgetEnumSysProp(java.lang.String propName, T defValue)
static int
getIntSysProp(java.lang.String propName, int defValue)
static ISqlJetMemoryPointer
getMoved(ISqlJetMemoryPointer preceding, ISqlJetMemoryPointer ptr, int offset)
static java.lang.String
getSysProp(java.lang.String propName, java.lang.String defValue)
static int
getUnsignedByte(ISqlJetMemoryPointer byteBuffer, int index)
Get unsigned byte from byte bufferstatic byte
getVarint(ISqlJetMemoryPointer p, int offset, long[] v)
static byte
getVarint(ISqlJetMemoryPointer p, long[] v)
Read a 64-bit variable-length integer from memory starting at p[0].static byte
getVarint32(ISqlJetMemoryPointer p, int[] v)
Read a 32-bit variable-length integer from memory starting at p[0].static byte
getVarint32(ISqlJetMemoryPointer p, int offset, int[] v)
static java.lang.Object[]
insertArray(java.lang.Object[] intoArray, java.lang.Object[] insertArray, int pos)
static boolean
isNumber(java.lang.String s, boolean[] realnum)
Return TRUE if z is a pure numeric string.static void
log(java.util.logging.Logger logger, java.lang.String format, java.lang.Object... args)
static int
memcmp(byte[] a1, byte[] a2, int count)
static int
memcmp(byte[] a1, int from1, byte[] a2, int from2, int count)
static int
memcmp(ISqlJetMemoryPointer a1, int a1offs, ISqlJetMemoryPointer a2, int a2offs, int count)
static int
memcmp(ISqlJetMemoryPointer a1, ISqlJetMemoryPointer a2, int count)
static void
memcpy(byte[] dest, byte[] src, int length)
static void
memcpy(byte[] dest, int dstPos, byte[] src, int srcPos, int length)
static void
memcpy(ISqlJetMemoryPointer dest, int dstPos, ISqlJetMemoryPointer src, int srcPos, int length)
static void
memcpy(ISqlJetMemoryPointer dest, ISqlJetMemoryPointer src, int length)
static void
memcpy(SqlJetCloneable[] dest, SqlJetCloneable[] src, int length)
static <T extends SqlJetCloneable>
Tmemcpy(T src)
static void
memmove(ISqlJetMemoryPointer dst, int dstOffs, ISqlJetMemoryPointer src, int srcOffs, int n)
static void
memmove(ISqlJetMemoryPointer dst, ISqlJetMemoryPointer src, int n)
static void
memset(ISqlJetMemoryPointer data, byte value)
static void
memset(ISqlJetMemoryPointer data, byte value, int count)
static void
memset(ISqlJetMemoryPointer data, int from, byte value, int count)
static void
movePtr(ISqlJetMemoryPointer p, int pos)
static boolean
mutex_held(ISqlJetMutex mutex)
static <E extends java.lang.Enum<E>>
java.util.EnumSet<E>noneOf(java.lang.Class<E> elementType)
static <E extends java.lang.Enum<E>>
java.util.EnumSet<E>of(E e)
static <E extends java.lang.Enum<E>>
java.util.EnumSet<E>of(E e1, E e2)
static <E extends java.lang.Enum<E>>
java.util.EnumSet<E>of(E e1, E... e)
static <E extends java.lang.Enum<E>>
java.util.EnumSet<E>of(E e1, E e2, E e3)
static ISqlJetMemoryPointer
pointer(ISqlJetMemoryPointer p)
static ISqlJetMemoryPointer
pointer(ISqlJetMemoryPointer p, int pos)
Implements address arithmetic on byte buffer.static void
put2byte(ISqlJetMemoryPointer p, int v)
Write a two-byte big-endian integer values.static void
put2byte(ISqlJetMemoryPointer p, int off, int v)
Write a two-byte big-endian integer values.static ISqlJetMemoryPointer
put4byte(int v)
Write a four-byte big-endian integer value.static void
put4byte(ISqlJetMemoryPointer p, int pos, long v)
Write a four-byte big-endian integer value.static void
put4byte(ISqlJetMemoryPointer p, long v)
Write a four-byte big-endian integer value.static void
put4byteUnsigned(byte[] p, int pos, long v)
Write a four-byte big-endian integer value.static ISqlJetMemoryPointer
put4byteUnsigned(long v)
Write a four-byte big-endian integer value.static void
put4byteUnsigned(ISqlJetMemoryPointer p, int pos, long v)
Write a four-byte big-endian integer value.static void
put4byteUnsigned(ISqlJetMemoryPointer p, long v)
Write a four-byte big-endian integer value.static ISqlJetMemoryPointer
putUnsignedByte(ISqlJetMemoryPointer byteBuffer, int index, int value)
Put unsigned byte to byte bufferstatic int
putVarint(ISqlJetMemoryPointer p, long v)
Write a 64-bit variable-length integer to memory starting at p[0].static int
putVarint32(ISqlJetMemoryPointer p, int v)
This routine is a faster version of sqlite3PutVarint() that only works for 32-bit positive integers and which is optimized for the common case of small integers.static byte[]
readByteBuffer(ISqlJetMemoryPointer buffer)
static int
sqlite3VarintLen(long v)
Return the number of bytes that will be needed to store the given 64-bit integer.static ISqlJetMemoryPointer
streamToBuffer(java.io.InputStream stream)
static int
strlen(byte[] s, int from)
static int
strlen(ISqlJetMemoryPointer s, int from)
static int
strlen30(ISqlJetMemoryPointer z)
Compute a string length that is limited to what can be stored in lower 30 bits of a 32-bit signed integer.static java.lang.String
toString(ISqlJetMemoryPointer buf)
Convert byte buffer to string.static java.lang.String
toString(ISqlJetMemoryPointer buf, SqlJetEncoding enc)
Convert byte buffer to string.static short
toUnsigned(byte value)
static long
toUnsigned(int value)
static int
toUnsigned(short value)
static ISqlJetMemoryPointer
translate(ISqlJetMemoryPointer buf, SqlJetEncoding from, SqlJetEncoding to)
TranslateByteBuffer
from one charset to other charset.static java.lang.String
trim(java.lang.String s)
static int
varintLen(long v)
Return the number of bytes that will be needed to store the given 64-bit integer.static ISqlJetMemoryPointer
wrapPtr(byte[] bs)
-
-
-
Field Detail
-
SQLJET_PACKAGENAME
public static final java.lang.String SQLJET_PACKAGENAME
- See Also:
- Constant Field Values
-
memoryManager
public static final ISqlJetMemoryManager memoryManager
-
-
Method Detail
-
log
public static void log(java.util.logging.Logger logger, java.lang.String format, java.lang.Object... args)
- Parameters:
logger
-format
-args
-
-
allocatePtr
public static final ISqlJetMemoryPointer allocatePtr(int size)
-
allocatePtr
public static final ISqlJetMemoryPointer allocatePtr(int size, SqlJetMemoryBufferType bufferType)
-
pointer
public static final ISqlJetMemoryPointer pointer(ISqlJetMemoryPointer p)
- Parameters:
buf
-- Returns:
-
pointer
public static final ISqlJetMemoryPointer pointer(ISqlJetMemoryPointer p, int pos)
Implements address arithmetic on byte buffer.- Parameters:
p
-pos
-- Returns:
-
movePtr
public static final void movePtr(ISqlJetMemoryPointer p, int pos)
-
wrapPtr
public static final ISqlJetMemoryPointer wrapPtr(byte[] bs)
- Parameters:
bs
-- Returns:
-
getSysProp
public static java.lang.String getSysProp(java.lang.String propName, java.lang.String defValue) throws SqlJetError
- Throws:
SqlJetError
-
getIntSysProp
public static int getIntSysProp(java.lang.String propName, int defValue) throws SqlJetError
- Throws:
SqlJetError
-
getBoolSysProp
public static boolean getBoolSysProp(java.lang.String propName, boolean defValue)
- Parameters:
string
-b
-- Returns:
-
getEnumSysProp
public static <T extends java.lang.Enum<T>> T getEnumSysProp(java.lang.String propName, T defValue)
- Type Parameters:
T
-- Parameters:
propName
-defValue
-- Returns:
-
get2byte
public static final int get2byte(ISqlJetMemoryPointer x)
Read a two-byte big-endian integer values.
-
get2byte
public static final int get2byte(ISqlJetMemoryPointer x, int off)
Read a two-byte big-endian integer values.
-
put2byte
public static final void put2byte(ISqlJetMemoryPointer p, int v)
Write a two-byte big-endian integer values.
-
put2byte
public static final void put2byte(ISqlJetMemoryPointer p, int off, int v)
Write a two-byte big-endian integer values.
-
put4byte
public static final ISqlJetMemoryPointer put4byte(int v)
Write a four-byte big-endian integer value.
-
get4byte
public static final int get4byte(ISqlJetMemoryPointer p)
Read a four-byte big-endian integer value.
-
get4byte
public static final int get4byte(ISqlJetMemoryPointer p, int pos)
Read a four-byte big-endian integer value.
-
put4byte
public static final void put4byte(ISqlJetMemoryPointer p, int pos, long v)
Write a four-byte big-endian integer value.
-
put4byte
public static final void put4byte(ISqlJetMemoryPointer p, long v)
Write a four-byte big-endian integer value.
-
memcpy
public static final void memcpy(byte[] dest, byte[] src, int length)
- Parameters:
dest
-src
-length
-
-
memcpy
public static final void memcpy(byte[] dest, int dstPos, byte[] src, int srcPos, int length)
-
memcpy
public static final void memcpy(ISqlJetMemoryPointer dest, ISqlJetMemoryPointer src, int length)
-
memcpy
public static final void memcpy(ISqlJetMemoryPointer dest, int dstPos, ISqlJetMemoryPointer src, int srcPos, int length)
-
memcpy
public static final void memcpy(SqlJetCloneable[] dest, SqlJetCloneable[] src, int length) throws SqlJetException
- Throws:
SqlJetException
-
memcpy
public static final <T extends SqlJetCloneable> T memcpy(T src) throws SqlJetException
- Throws:
SqlJetException
-
memset
public static final void memset(ISqlJetMemoryPointer data, int from, byte value, int count)
- Parameters:
data
-from
-value
-count
-
-
memset
public static final void memset(ISqlJetMemoryPointer data, byte value, int count)
- Parameters:
data
-value
-count
-
-
memset
public static final void memset(ISqlJetMemoryPointer data, byte value)
- Parameters:
data
-value
-
-
strlen
public static int strlen(byte[] s, int from)
- Parameters:
s
-from
-- Returns:
-
strlen
public static int strlen(ISqlJetMemoryPointer s, int from)
-
bitSetTest
public static boolean bitSetTest(java.util.BitSet bitSet, int index)
Check to see if the i-th bit is set. Return true or false. If p is NULL (if the bitmap has not been created) or if i is out of range, then return false.- Parameters:
bitSet
-index
-- Returns:
-
memcmp
public static final int memcmp(byte[] a1, byte[] a2, int count)
- Parameters:
magic
-journalMagic
-i
-- Returns:
-
memcmp
public static final int memcmp(byte[] a1, int from1, byte[] a2, int from2, int count)
-
memcmp
public static final int memcmp(ISqlJetMemoryPointer a1, ISqlJetMemoryPointer a2, int count)
- Parameters:
z
-z2
-count
-- Returns:
-
memcmp
public static final int memcmp(ISqlJetMemoryPointer a1, int a1offs, ISqlJetMemoryPointer a2, int a2offs, int count)
- Parameters:
z
-z2
-count
-- Returns:
-
addZeroByteEnd
public static byte[] addZeroByteEnd(byte[] b)
- Parameters:
b
-- Returns:
-
getBytes
public static byte[] getBytes(java.lang.String string)
- Parameters:
sqliteFileHeader
-- Returns:
-
putVarint
public static int putVarint(ISqlJetMemoryPointer p, long v)
Write a 64-bit variable-length integer to memory starting at p[0]. The length of data write will be between 1 and 9 bytes. The number of bytes written is returned. A variable-length integer consists of the lower 7 bits of each byte for all bytes that have the 8th bit set and one byte with the 8th bit clear. Except, if we get to the 9th byte, it stores the full 8 bits and is the last byte.
-
putVarint32
public static int putVarint32(ISqlJetMemoryPointer p, int v)
This routine is a faster version of sqlite3PutVarint() that only works for 32-bit positive integers and which is optimized for the common case of small integers. A MACRO version, putVarint32, is provided which inlines the single-byte case. All code should use the MACRO version as this function assumes the single-byte case has already been handled.
-
getVarint
public static byte getVarint(ISqlJetMemoryPointer p, long[] v)
Read a 64-bit variable-length integer from memory starting at p[0]. Return the number of bytes read. The value is stored in *v.
-
getVarint
public static byte getVarint(ISqlJetMemoryPointer p, int offset, long[] v)
-
getVarint32
public static byte getVarint32(ISqlJetMemoryPointer p, int[] v)
Read a 32-bit variable-length integer from memory starting at p[0]. Return the number of bytes read. The value is stored in *v. A MACRO version, getVarint32, is provided which inlines the single-byte case. All code should use the MACRO version as this function assumes the single-byte case has already been handled.- Throws:
SqlJetExceptionRemove
-
getVarint32
public static byte getVarint32(ISqlJetMemoryPointer p, int offset, int[] v)
-
sqlite3VarintLen
public static int sqlite3VarintLen(long v)
Return the number of bytes that will be needed to store the given 64-bit integer.
-
mutex_held
public static final boolean mutex_held(ISqlJetMutex mutex)
- Parameters:
mutex
-- Returns:
-
strlen30
public static int strlen30(ISqlJetMemoryPointer z)
Compute a string length that is limited to what can be stored in lower 30 bits of a 32-bit signed integer.- Parameters:
z
-- Returns:
-
getUnsignedByte
public static final int getUnsignedByte(ISqlJetMemoryPointer byteBuffer, int index)
Get unsigned byte from byte buffer- Parameters:
byteBuffer
-index
-- Returns:
-
putUnsignedByte
public static final ISqlJetMemoryPointer putUnsignedByte(ISqlJetMemoryPointer byteBuffer, int index, int value)
Put unsigned byte to byte buffer- Parameters:
byteBuffer
-index
-value
-- Returns:
-
toString
public static java.lang.String toString(ISqlJetMemoryPointer buf)
Convert byte buffer to string.- Parameters:
buf
-- Returns:
-
toString
public static java.lang.String toString(ISqlJetMemoryPointer buf, SqlJetEncoding enc) throws SqlJetException
Convert byte buffer to string.- Parameters:
buf
-- Returns:
- Throws:
SqlJetException
-
fromString
public static ISqlJetMemoryPointer fromString(java.lang.String s, SqlJetEncoding enc) throws SqlJetException
GetByteBuffer
fromString
.- Parameters:
s
-enc
-- Returns:
- Throws:
SqlJetException
-
translate
public static ISqlJetMemoryPointer translate(ISqlJetMemoryPointer buf, SqlJetEncoding from, SqlJetEncoding to) throws SqlJetException
TranslateByteBuffer
from one charset to other charset.- Parameters:
buf
-from
-to
-- Returns:
- Throws:
SqlJetException
-
trim
public static final java.lang.String trim(java.lang.String s)
- Parameters:
s
-- Returns:
-
varintLen
public static int varintLen(long v)
Return the number of bytes that will be needed to store the given 64-bit integer.
-
toUnsigned
public static final short toUnsigned(byte value)
-
fromUnsigned
public static final byte fromUnsigned(short value)
-
toUnsigned
public static final int toUnsigned(short value)
-
fromUnsigned
public static final short fromUnsigned(int value)
-
toUnsigned
public static long toUnsigned(int value)
-
fromUnsigned
public static final int fromUnsigned(long value)
-
get4byteUnsigned
public static final long get4byteUnsigned(byte[] p)
Read a four-byte big-endian integer value.
-
get4byteUnsigned
public static final long get4byteUnsigned(byte[] p, int pos)
Read a four-byte big-endian integer value.
-
put4byteUnsigned
public static final ISqlJetMemoryPointer put4byteUnsigned(long v)
Write a four-byte big-endian integer value.
-
put4byteUnsigned
public static final void put4byteUnsigned(byte[] p, int pos, long v)
Write a four-byte big-endian integer value.
-
get4byteUnsigned
public static final long get4byteUnsigned(ISqlJetMemoryPointer p)
Read a four-byte big-endian integer value.
-
get4byteUnsigned
public static final long get4byteUnsigned(ISqlJetMemoryPointer p, int pos)
Read a four-byte big-endian integer value.
-
put4byteUnsigned
public static final void put4byteUnsigned(ISqlJetMemoryPointer p, int pos, long v)
Write a four-byte big-endian integer value.
-
put4byteUnsigned
public static final void put4byteUnsigned(ISqlJetMemoryPointer p, long v)
Write a four-byte big-endian integer value.
-
memmove
public static final void memmove(ISqlJetMemoryPointer dst, ISqlJetMemoryPointer src, int n)
- Parameters:
z
-slice
-n
-
-
memmove
public static final void memmove(ISqlJetMemoryPointer dst, int dstOffs, ISqlJetMemoryPointer src, int srcOffs, int n)
- Parameters:
z
-slice
-n
-
-
atof
public static final double atof(ISqlJetMemoryPointer z)
- Parameters:
z
-- Returns:
-
atoi64
public static final java.lang.Long atoi64(java.lang.String str)
- Parameters:
str
-- Returns:
-
absolute
public static final long absolute(long i)
Returns absolute value of argument- Parameters:
i
-- Returns:
-
addArrays
public static final java.lang.Object[] addArrays(java.lang.Object[] array1, java.lang.Object[] array2)
- Parameters:
key
-dataRowId
-- Returns:
-
insertArray
public static final java.lang.Object[] insertArray(java.lang.Object[] intoArray, java.lang.Object[] insertArray, int pos)
-
of
public static final <E extends java.lang.Enum<E>> java.util.EnumSet<E> of(E e1, E... e)
-
of
public static final <E extends java.lang.Enum<E>> java.util.EnumSet<E> of(E e)
-
of
public static final <E extends java.lang.Enum<E>> java.util.EnumSet<E> of(E e1, E e2)
-
of
public static final <E extends java.lang.Enum<E>> java.util.EnumSet<E> of(E e1, E e2, E e3)
-
noneOf
public static final <E extends java.lang.Enum<E>> java.util.EnumSet<E> noneOf(java.lang.Class<E> elementType)
-
adjustNumberTypes
public static final java.lang.Object[] adjustNumberTypes(java.lang.Object[] key)
- Parameters:
key
-- Returns:
-
adjustScopeNumberTypes
public static final SqlJetScope adjustScopeNumberTypes(SqlJetScope scope)
-
adjustNumberType
public static final java.lang.Object adjustNumberType(java.lang.Object value)
-
streamToBuffer
public static ISqlJetMemoryPointer streamToBuffer(java.io.InputStream stream) throws SqlJetException
- Parameters:
value
-- Returns:
- Throws:
SqlJetException
-
readByteBuffer
public static byte[] readByteBuffer(ISqlJetMemoryPointer buffer)
- Parameters:
buffer
-- Returns:
-
copyArray
public static java.lang.Object[] copyArray(java.lang.Object[] array)
- Parameters:
firstKey
-- Returns:
-
isNumber
public static boolean isNumber(java.lang.String s, boolean[] realnum)
Return TRUE if z is a pure numeric string. Return FALSE and leave realnum unchanged if the string contains any character which is not part of a number. If the string is pure numeric, set realnum to TRUE if the string contains the '.' character or an "E+000" style exponentiation suffix. Otherwise set realnum to FALSE. Note that just becaue realnum is false does not mean that the number can be successfully converted into an integer - it might be too big. An empty string is considered non-numeric.- Parameters:
s
-realnum
-- Returns:
-
doubleToInt64
public static java.lang.Long doubleToInt64(java.lang.Double r)
- Parameters:
r
-- Returns:
-
fromByteBuffer
public static ISqlJetMemoryPointer fromByteBuffer(java.nio.ByteBuffer b)
- Parameters:
value
-- Returns:
-
getMoved
public static ISqlJetMemoryPointer getMoved(ISqlJetMemoryPointer preceding, ISqlJetMemoryPointer ptr, int offset)
-
-