## org.h2.dev.store.btree
Class DataUtils

    java.lang.Object
      org.h2.dev.store.btree.DataUtils

    public class DataUtils

extends java.lang.Object

Utility methods

Field Summary
`static int` `MAX_VAR_INT_LEN` The maximum length of a variable size int.
`static int` `MAX_VAR_LONG_LEN` The maximum length of a variable size long.
`static int` `PAGE_COMPRESSED` The bit mask for compressed pages.
`static int` `PAGE_TYPE_LEAF` The type for leaf page.
`static int` `PAGE_TYPE_NODE` The type for node page.

Constructor Summary
`DataUtils()`

Method Summary
`static void` `appendMap(java.lang.StringBuilder buff, java.lang.String key, java.lang.Object value)` Append a key-value pair to the string buffer.
`static void` `copyExcept(java.lang.Object src, java.lang.Object dst, int oldSize, int removeIndex)` Copy the elements of an array, and remove one element.
`static void` `copyWithGap(java.lang.Object src, java.lang.Object dst, int oldSize, int gapIndex)` Copy the elements of an array, with a gap.
`static int` `encodeLength(int len)` Convert the length to a length code 0..31. 31 means more than 1 MB.
`static short` `getCheckValue(int x)` Calculate a check value for the given integer.
`static int` `getPageChunkId(long pos)` Get the chunk id from the position.
`static int` `getPageMaxLength(long pos)` Get the maximum length for the given code.
`static int` `getPageOffset(long pos)` Get the offset from the position.
`static long` `getPagePos(int chunkId, int offset, int length, int type)` Get the position of this page.
`static int` `getPageType(long pos)` Get the page type from the position.
`static int` `getVarIntLen(int x)` Get the length of the variable size int.
`static int` `getVarLongLen(long x)` Get the length of the variable size long.
`static java.util.HashMap<java.lang.String,java.lang.String>` `parseMap(java.lang.String s)` Parse a key-value pair list.
`static void` `readFully(java.nio.channels.FileChannel file, java.nio.ByteBuffer buff)` Read from a file channel until the target buffer is full, or end-of-file has been reached.
`static int` `readVarInt(java.nio.ByteBuffer buff)` Read a variable size int.
`static long` `readVarLong(java.nio.ByteBuffer buff)` Read a variable size long.
`static void` `writeVarInt(java.nio.ByteBuffer buff, int x)` Write a variable size int.
`static void` `writeVarLong(java.nio.ByteBuffer buff, long x)` Write a variable size int.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PAGE_TYPE_LEAF

    public static final int PAGE_TYPE_LEAF

  The type for leaf page.

  See Also:
    Constant Field Values

### PAGE_TYPE_NODE

    public static final int PAGE_TYPE_NODE

  The type for node page.

  See Also:
    Constant Field Values

### PAGE_COMPRESSED

    public static final int PAGE_COMPRESSED

  The bit mask for compressed pages.

  See Also:
    Constant Field Values

### MAX_VAR_INT_LEN

    public static final int MAX_VAR_INT_LEN

  The maximum length of a variable size int.

  See Also:
    Constant Field Values

### MAX_VAR_LONG_LEN

    public static final int MAX_VAR_LONG_LEN

  The maximum length of a variable size long.

  See Also:
    Constant Field Values

Constructor Detail

### DataUtils

    public DataUtils()

Method Detail

### getVarIntLen

    public static int getVarIntLen(int x)

  Get the length of the variable size int.

  Parameters:
    `x` - the value
  Returns:
    the length in bytes

### getVarLongLen

    public static int getVarLongLen(long x)

  Get the length of the variable size long.

  Parameters:
    `x` - the value
  Returns:
    the length in bytes

### readVarInt

    public static int readVarInt(java.nio.ByteBuffer buff)

  Read a variable size int.

  Parameters:
    `buff` - the source buffer
  Returns:
    the value

### readVarLong

    public static long readVarLong(java.nio.ByteBuffer buff)

  Read a variable size long.

  Parameters:
    `buff` - the source buffer
  Returns:
    the value

### writeVarInt

    public static void writeVarInt(java.nio.ByteBuffer buff,
                                   int x)

  Write a variable size int.

  Parameters:
    `buff` - the target buffer
    `x` - the value

### writeVarLong

    public static void writeVarLong(java.nio.ByteBuffer buff,
                                    long x)

  Write a variable size int.

  Parameters:
    `buff` - the target buffer
    `x` - the value

### copyWithGap

    public static void copyWithGap(java.lang.Object src,
                                   java.lang.Object dst,
                                   int oldSize,
                                   int gapIndex)

  Copy the elements of an array, with a gap.

  Parameters:
    `src` - the source array
    `dst` - the target array
    `oldSize` - the size of the old array
    `gapIndex` - the index of the gap

### copyExcept

    public static void copyExcept(java.lang.Object src,
                                  java.lang.Object dst,
                                  int oldSize,
                                  int removeIndex)

  Copy the elements of an array, and remove one element.

  Parameters:
    `src` - the source array
    `dst` - the target array
    `oldSize` - the size of the old array
    `removeIndex` - the index of the entry to remove

### readFully

    public static void readFully(java.nio.channels.FileChannel file,
                                 java.nio.ByteBuffer buff)
                          throws java.io.IOException

  Read from a file channel until the target buffer is full, or end-of-file has been reached.

  Parameters:
    `file` - the file channel
    `buff` - the target buffer
  Throws:
    `java.io.IOException`

### encodeLength

    public static int encodeLength(int len)

  Convert the length to a length code 0..31. 31 means more than 1 MB.

  Parameters:
    `len` - the length
  Returns:
    the length code

### getPageChunkId

    public static int getPageChunkId(long pos)

  Get the chunk id from the position.

  Parameters:
    `pos` - the position
  Returns:
    the chunk id

### getPageMaxLength

    public static int getPageMaxLength(long pos)

  Get the maximum length for the given code. For the code 31, Integer.MAX_VALUE is returned.

  Parameters:
    `pos` - the position
  Returns:
    the maximum length

### getPageOffset

    public static int getPageOffset(long pos)

  Get the offset from the position.

  Parameters:
    `pos` - the position
  Returns:
    the offset

### getPageType

    public static int getPageType(long pos)

  Get the page type from the position.

  Parameters:
    `pos` - the position
  Returns:
    the page type (PAGE_TYPE_NODE or PAGE_TYPE_LEAF)

### getPagePos

    public static long getPagePos(int chunkId,
                                  int offset,
                                  int length,
                                  int type)

  Get the position of this page. The following information is encoded in the position: the chunk id, the offset, the maximum length, and the type (node or leaf).

  Parameters:
    `chunkId` - the chunk id
    `offset` - the offset
    `length` - the length
    `type` - the page type (1 for node, 0 for leaf)
  Returns:
    the position

### getCheckValue

    public static short getCheckValue(int x)

  Calculate a check value for the given integer. A check value is mean to verify the data is consistent with a high probability, but not meant to protect against media failure or deliberate changes.

  Parameters:
    `x` - the value
  Returns:
    the check value

### appendMap

    public static void appendMap(java.lang.StringBuilder buff,
                                 java.lang.String key,
                                 java.lang.Object value)

  Append a key-value pair to the string buffer. Keys may not contain a colon. Values that contain a comma or a double quote are enclosed in double quotes, with special characters escaped using a backslash.

  Parameters:
    `buff` - the target buffer
    `key` - the key
    `value` - the value

### parseMap

    public static java.util.HashMap<java.lang.String,java.lang.String> parseMap(java.lang.String s)

  Parse a key-value pair list.

  Parameters:
    `s` - the list
  Returns:
    the map