public final class DataUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DataUtils.MapEntry<K,V>
An entry of a map.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
COMPRESSED_VAR_INT_MAX
The maximum integer that needs less space when using variable size
encoding (only 3 bytes instead of 4).
|
static long |
COMPRESSED_VAR_LONG_MAX
The maximum long that needs less space when using variable size
encoding (only 7 bytes instead of 8).
|
static int |
ERROR_BLOCK_NOT_FOUND
The block in the stream store was not found.
|
static int |
ERROR_CHUNK_NOT_FOUND
The application was trying to read data from a chunk that is no longer
available.
|
static int |
ERROR_CLOSED
The object is already closed.
|
static int |
ERROR_FILE_CORRUPT
The file is corrupt or (for encrypted files) the encryption key is wrong.
|
static int |
ERROR_FILE_LOCKED
The file is locked.
|
static int |
ERROR_INTERNAL
An internal error occurred.
|
static int |
ERROR_READING_FAILED
An error occurred while reading from the file.
|
static int |
ERROR_SERIALIZATION
An error occurred when serializing or de-serializing.
|
static int |
ERROR_TOO_MANY_OPEN_TRANSACTIONS
There are too many open transactions.
|
static int |
ERROR_TRANSACTION_CORRUPT
The transaction store is corrupt.
|
static int |
ERROR_TRANSACTION_ILLEGAL_STATE
The transaction store is in an illegal state (for example, not yet
initialized).
|
static int |
ERROR_TRANSACTION_LOCKED
An entry is still locked by another transaction.
|
static int |
ERROR_UNSUPPORTED_FORMAT
The file format is not supported.
|
static int |
ERROR_WRITING_FAILED
An error occurred when trying to write to the file.
|
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 (compression level fast).
|
static int |
PAGE_COMPRESSED_HIGH
The bit mask for compressed pages (compression level high).
|
static int |
PAGE_LARGE
The marker size of a very large page.
|
static int |
PAGE_MEMORY
The estimated number of bytes used per page object.
|
static int |
PAGE_MEMORY_CHILD
The estimated number of bytes used per child entry.
|
static int |
PAGE_TYPE_LEAF
The type for leaf page.
|
static int |
PAGE_TYPE_NODE
The type for node page.
|
| Constructor and Description |
|---|
DataUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.StringBuilder |
appendMap(java.lang.StringBuilder buff,
java.util.HashMap<java.lang.String,?> map)
Append a map to the string builder, sorted by key.
|
static void |
appendMap(java.lang.StringBuilder buff,
java.lang.String key,
int value)
Append a key-value pair to the string builder.
|
static void |
appendMap(java.lang.StringBuilder buff,
java.lang.String key,
long value)
Append a key-value pair to the string builder.
|
static void |
appendMap(java.lang.StringBuilder buff,
java.lang.String key,
java.lang.String value)
Append a key-value pair to the string builder.
|
static void |
checkArgument(boolean test,
java.lang.String message,
java.lang.Object... arguments)
Throw an IllegalArgumentException if the argument is invalid.
|
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.
|
static java.lang.String |
formatMessage(int errorCode,
java.lang.String message,
java.lang.Object... arguments)
Format an error message.
|
static short |
getCheckValue(int x)
Calculate a check value for the given integer.
|
static int |
getConfigParam(java.util.Map<java.lang.String,?> config,
java.lang.String key,
int defaultValue)
Get the configuration parameter value, or default.
|
static int |
getErrorCode(java.lang.String m)
Get the error code from an exception message.
|
static int |
getFletcher32(byte[] bytes,
int offset,
int length)
Calculate the Fletcher32 checksum.
|
static java.lang.String |
getFromMap(java.lang.String s,
java.lang.String key)
Parse a specified pair from key-value pair list.
|
static java.lang.String |
getMapName(java.lang.String s)
Parse a name from key-value pair list.
|
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.lang.IllegalArgumentException |
newIllegalArgumentException(java.lang.String message,
java.lang.Object... arguments)
Create a new IllegalArgumentException.
|
static java.lang.IllegalStateException |
newIllegalStateException(int errorCode,
java.lang.String message,
java.lang.Object... arguments)
Create a new IllegalStateException.
|
static java.lang.UnsupportedOperationException |
newUnsupportedOperationException(java.lang.String message)
Create a new UnsupportedOperationException.
|
static java.util.HashMap<java.lang.String,java.lang.String> |
parseChecksummedMap(byte[] bytes)
Parse a key-value pair list and checks its checksum.
|
static int |
parseHexInt(java.lang.String x)
Parse an unsigned, hex long.
|
static long |
parseHexLong(java.lang.String x)
Parse an unsigned, hex 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,
long pos,
java.nio.ByteBuffer dst)
Read from a file channel until the buffer is full.
|
static int |
readHexInt(java.util.HashMap<java.lang.String,?> map,
java.lang.String key,
int defaultValue)
Read a hex int value from a map.
|
static long |
readHexLong(java.util.Map<java.lang.String,?> map,
java.lang.String key,
long defaultValue)
Read a hex long value from a map.
|
static java.lang.String |
readString(java.nio.ByteBuffer buff,
int len)
Read a string.
|
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 |
writeFully(java.nio.channels.FileChannel file,
long pos,
java.nio.ByteBuffer src)
Write to a file channel.
|
static void |
writeStringData(java.nio.ByteBuffer buff,
java.lang.String s,
int len)
Write characters from a string (without the length).
|
static void |
writeVarInt(java.nio.ByteBuffer buff,
int x)
Write a variable size int.
|
static void |
writeVarInt(java.io.OutputStream out,
int x)
Write a variable size int.
|
static void |
writeVarLong(java.nio.ByteBuffer buff,
long x)
Write a variable size long.
|
static void |
writeVarLong(java.io.OutputStream out,
long x)
Write a variable size long.
|
public static final int ERROR_READING_FAILED
public static final int ERROR_WRITING_FAILED
public static final int ERROR_INTERNAL
public static final int ERROR_CLOSED
public static final int ERROR_UNSUPPORTED_FORMAT
public static final int ERROR_FILE_CORRUPT
public static final int ERROR_FILE_LOCKED
public static final int ERROR_SERIALIZATION
public static final int ERROR_CHUNK_NOT_FOUND
public static final int ERROR_BLOCK_NOT_FOUND
public static final int ERROR_TRANSACTION_CORRUPT
public static final int ERROR_TRANSACTION_LOCKED
public static final int ERROR_TOO_MANY_OPEN_TRANSACTIONS
public static final int ERROR_TRANSACTION_ILLEGAL_STATE
public static final int PAGE_TYPE_LEAF
public static final int PAGE_TYPE_NODE
public static final int PAGE_COMPRESSED
public static final int PAGE_COMPRESSED_HIGH
public static final int MAX_VAR_INT_LEN
public static final int MAX_VAR_LONG_LEN
public static final int COMPRESSED_VAR_INT_MAX
public static final long COMPRESSED_VAR_LONG_MAX
public static final int PAGE_MEMORY
public static final int PAGE_MEMORY_CHILD
public static final int PAGE_LARGE
public static int getVarIntLen(int x)
x - the valuepublic static int getVarLongLen(long x)
x - the valuepublic static int readVarInt(java.nio.ByteBuffer buff)
buff - the source bufferpublic static long readVarLong(java.nio.ByteBuffer buff)
buff - the source bufferpublic static void writeVarInt(java.io.OutputStream out,
int x)
throws java.io.IOException
out - the output streamx - the valuejava.io.IOExceptionpublic static void writeVarInt(java.nio.ByteBuffer buff,
int x)
buff - the source bufferx - the valuepublic static void writeStringData(java.nio.ByteBuffer buff,
java.lang.String s,
int len)
buff - the target buffer (must be large enough)s - the stringlen - the number of characterspublic static java.lang.String readString(java.nio.ByteBuffer buff,
int len)
buff - the source bufferlen - the number of characterspublic static void writeVarLong(java.nio.ByteBuffer buff,
long x)
buff - the target bufferx - the valuepublic static void writeVarLong(java.io.OutputStream out,
long x)
throws java.io.IOException
out - the output streamx - the valuejava.io.IOExceptionpublic static void copyWithGap(java.lang.Object src,
java.lang.Object dst,
int oldSize,
int gapIndex)
src - the source arraydst - the target arrayoldSize - the size of the old arraygapIndex - the index of the gappublic static void copyExcept(java.lang.Object src,
java.lang.Object dst,
int oldSize,
int removeIndex)
src - the source arraydst - the target arrayoldSize - the size of the old arrayremoveIndex - the index of the entry to removepublic static void readFully(java.nio.channels.FileChannel file,
long pos,
java.nio.ByteBuffer dst)
file - the file channelpos - the absolute position within the filedst - the byte bufferjava.lang.IllegalStateException - if some data could not be readpublic static void writeFully(java.nio.channels.FileChannel file,
long pos,
java.nio.ByteBuffer src)
file - the file channelpos - the absolute position within the filesrc - the source bufferpublic static int encodeLength(int len)
len - the lengthpublic static int getPageChunkId(long pos)
pos - the positionpublic static int getPageMaxLength(long pos)
pos - the positionpublic static int getPageOffset(long pos)
pos - the positionpublic static int getPageType(long pos)
pos - the positionpublic static long getPagePos(int chunkId,
int offset,
int length,
int type)
chunkId - the chunk idoffset - the offsetlength - the lengthtype - the page type (1 for node, 0 for leaf)public static short getCheckValue(int x)
x - the valuepublic static java.lang.StringBuilder appendMap(java.lang.StringBuilder buff,
java.util.HashMap<java.lang.String,?> map)
buff - the target buffermap - the mappublic static void appendMap(java.lang.StringBuilder buff,
java.lang.String key,
java.lang.String value)
buff - the target bufferkey - the keyvalue - the valuepublic static void appendMap(java.lang.StringBuilder buff,
java.lang.String key,
long value)
buff - the target bufferkey - the keyvalue - the valuepublic static void appendMap(java.lang.StringBuilder buff,
java.lang.String key,
int value)
buff - the target bufferkey - the keyvalue - the valuepublic static java.util.HashMap<java.lang.String,java.lang.String> parseMap(java.lang.String s)
s - the listjava.lang.IllegalStateException - if parsing failedpublic static java.util.HashMap<java.lang.String,java.lang.String> parseChecksummedMap(byte[] bytes)
bytes - encoded map"fletcher", or null if checksum is wrongjava.lang.IllegalStateException - if parsing failedpublic static java.lang.String getMapName(java.lang.String s)
s - the listnulljava.lang.IllegalStateException - if parsing failedpublic static java.lang.String getFromMap(java.lang.String s,
java.lang.String key)
s - the listkey - the name of the keynulljava.lang.IllegalStateException - if parsing failedpublic static int getFletcher32(byte[] bytes,
int offset,
int length)
bytes - the bytesoffset - initial offsetlength - the message length (if odd, 0 is appended)public static void checkArgument(boolean test,
java.lang.String message,
java.lang.Object... arguments)
test - true if the argument is validmessage - the messagearguments - the argumentsjava.lang.IllegalArgumentException - if the argument is invalidpublic static java.lang.IllegalArgumentException newIllegalArgumentException(java.lang.String message,
java.lang.Object... arguments)
message - the messagearguments - the argumentspublic static java.lang.UnsupportedOperationException newUnsupportedOperationException(java.lang.String message)
message - the messagepublic static java.lang.IllegalStateException newIllegalStateException(int errorCode,
java.lang.String message,
java.lang.Object... arguments)
errorCode - the error codemessage - the messagearguments - the argumentspublic static java.lang.String formatMessage(int errorCode,
java.lang.String message,
java.lang.Object... arguments)
errorCode - the error codemessage - the messagearguments - the argumentspublic static int getErrorCode(java.lang.String m)
m - the messagepublic static long readHexLong(java.util.Map<java.lang.String,?> map,
java.lang.String key,
long defaultValue)
map - the mapkey - the keydefaultValue - if the value is nulljava.lang.IllegalStateException - if parsing failspublic static long parseHexLong(java.lang.String x)
x - the stringjava.lang.IllegalStateException - if parsing failspublic static int parseHexInt(java.lang.String x)
x - the stringjava.lang.IllegalStateException - if parsing failspublic static int readHexInt(java.util.HashMap<java.lang.String,?> map,
java.lang.String key,
int defaultValue)
map - the mapkey - the keydefaultValue - if the value is nulljava.lang.IllegalStateException - if parsing failspublic static int getConfigParam(java.util.Map<java.lang.String,?> config,
java.lang.String key,
int defaultValue)
config - the configurationkey - the keydefaultValue - the default