Class SqlJetUtility

java.lang.Object
org.tmatesoft.sqljet.core.internal.SqlJetUtility

public final class SqlJetUtility extends Object
Author:
TMate Software Ltd., Sergey Scherbina (sergey.scherbina@gmail.com)
  • Field Details

  • Constructor Details

    • SqlJetUtility

      public SqlJetUtility()
  • Method Details

    • log

      public static void log(Logger logger, String format, 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 String getSysProp(String propName, String defValue) throws SqlJetError
      Throws:
      SqlJetError
    • getIntSysProp

      public static int getIntSysProp(String propName, int defValue) throws SqlJetError
      Throws:
      SqlJetError
    • getBoolSysProp

      public static boolean getBoolSysProp(String propName, boolean defValue)
      Parameters:
      string -
      b -
      Returns:
    • getEnumSysProp

      public static <T extends Enum<T>> T getEnumSysProp(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(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(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 String toString(ISqlJetMemoryPointer buf)
      Convert byte buffer to string.
      Parameters:
      buf -
      Returns:
    • toString

      public static String toString(ISqlJetMemoryPointer buf, SqlJetEncoding enc) throws SqlJetException
      Convert byte buffer to string.
      Parameters:
      buf -
      Returns:
      Throws:
      SqlJetException
    • fromString

      public static ISqlJetMemoryPointer fromString(String s, SqlJetEncoding enc) throws SqlJetException
      Get ByteBuffer from String.
      Parameters:
      s -
      enc -
      Returns:
      Throws:
      SqlJetException
    • translate

      Translate ByteBuffer from one charset to other charset.
      Parameters:
      buf -
      from -
      to -
      Returns:
      Throws:
      SqlJetException
    • trim

      public static final String trim(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 Long atoi64(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 Object[] addArrays(Object[] array1, Object[] array2)
      Parameters:
      key -
      dataRowId -
      Returns:
    • insertArray

      public static final Object[] insertArray(Object[] intoArray, Object[] insertArray, int pos)
    • of

      public static final <E extends Enum<E>> EnumSet<E> of(E e1, E... e)
    • of

      public static final <E extends Enum<E>> EnumSet<E> of(E e)
    • of

      public static final <E extends Enum<E>> EnumSet<E> of(E e1, E e2)
    • of

      public static final <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3)
    • noneOf

      public static final <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
    • adjustNumberTypes

      public static final Object[] adjustNumberTypes(Object[] key)
      Parameters:
      key -
      Returns:
    • adjustScopeNumberTypes

      public static final SqlJetScope adjustScopeNumberTypes(SqlJetScope scope)
    • adjustNumberType

      public static final Object adjustNumberType(Object value)
    • streamToBuffer

      public static ISqlJetMemoryPointer streamToBuffer(InputStream stream) throws SqlJetException
      Parameters:
      value -
      Returns:
      Throws:
      SqlJetException
    • readByteBuffer

      public static byte[] readByteBuffer(ISqlJetMemoryPointer buffer)
      Parameters:
      buffer -
      Returns:
    • copyArray

      public static Object[] copyArray(Object[] array)
      Parameters:
      firstKey -
      Returns:
    • isNumber

      public static boolean isNumber(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 Long doubleToInt64(Double r)
      Parameters:
      r -
      Returns:
    • fromByteBuffer

      public static ISqlJetMemoryPointer fromByteBuffer(ByteBuffer b)
      Parameters:
      value -
      Returns:
    • getMoved

      public static ISqlJetMemoryPointer getMoved(ISqlJetMemoryPointer preceding, ISqlJetMemoryPointer ptr, int offset)