com.sleepycat.je.log
Class LogUtils

java.lang.Object
  extended by com.sleepycat.je.log.LogUtils

public class LogUtils
extends Object

This class holds convenience methods for marshalling internal JE data to and from the log.


Nested Class Summary
static class LogUtils.XidImpl
           
 
Field Summary
static int INT_BYTES
           
static int LONG_BYTES
           
static int SHORT_BYTES
           
static int UNSIGNED_INT_BYTES
           
static byte[] ZERO_LENGTH_BYTE_ARRAY
           
 
Constructor Summary
LogUtils()
           
 
Method Summary
static boolean dumpBoolean(ByteBuffer itemBuffer, StringBuilder sb, String tag)
           
static int getBooleanLogSize()
           
static int getByteArrayLogSize(byte[] b)
           
static int getIntLogSize()
           
static int getLongLogSize()
           
static int getPackedIntLogSize(int i)
           
static int getPackedLongLogSize(long l)
           
static int getStringLogSize(String s)
           
static int getTimestampLogSize(Timestamp time)
           
static int getXidSize(Xid xid)
          The byte[]'s in Xid's are known to be 255 or less in length.
static boolean readBoolean(ByteBuffer logBuf)
          Read a boolean from the log.
static byte[] readByteArray(ByteBuffer logBuf, boolean unpacked)
          Read a byte array from the log.
static byte[] readBytesNoLength(ByteBuffer logBuf, int size)
          Read a byte array from the log.
static int readInt(ByteBuffer logBuf)
          Read a int from the log.
static int readInt(ByteBuffer logBuf, boolean unpacked)
          Read an int from the log in either packed or unpacked format.
static int readIntMSB(ByteBuffer logBuf)
          Read a int from the log in MSB order.
static long readLong(ByteBuffer logBuf)
          Read a long from the log.
static long readLong(ByteBuffer logBuf, boolean unpacked)
          Read an int from the log in either packed or unpacked format.
static int readPackedInt(ByteBuffer logBuf)
          Read a packed int from the log.
static long readPackedLong(ByteBuffer logBuf)
          Read a packed long from the log.
static short readShort(ByteBuffer logBuf)
          Read a short from the log.
static String readString(ByteBuffer logBuf, boolean unpacked)
          Read a string from the log.
static Timestamp readTimestamp(ByteBuffer logBuf, boolean unpacked)
          Read a timestamp from the log.
static long readUnsignedInt(ByteBuffer buf)
          Unmarshall the next four bytes which hold an unsigned int into a long.
static Xid readXid(ByteBuffer logBuf)
           
static void writeBoolean(ByteBuffer logBuf, boolean bool)
          Write a boolean into the log.
static void writeByteArray(ByteBuffer logBuf, byte[] b)
          Write a byte array into the log.
static void writeBytesNoLength(ByteBuffer logBuf, byte[] b)
          Write a byte array into the log.
static void writeInt(ByteBuffer logBuf, int i)
          Write an int into the log.
static void writeIntMSB(ByteBuffer logBuf, int i)
          Write an int into the log in MSB order.
static void writeLong(ByteBuffer logBuf, long l)
          Write a long into the log.
static void writePackedInt(ByteBuffer logBuf, int i)
          Write a packed int into the log.
static void writePackedLong(ByteBuffer logBuf, long l)
          Write a packed long into the log.
static void writeShort(ByteBuffer logBuf, short i)
          Write a short into the log.
static void writeString(ByteBuffer logBuf, String stringVal)
          Write a string into the log.
static void writeTimestamp(ByteBuffer logBuf, Timestamp time)
          Write a timestamp into the log.
static void writeUnsignedInt(ByteBuffer buf, long value)
          Marshall a long into the next 4 bytes in this buffer.
static void writeXid(ByteBuffer logBuf, Xid xid)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHORT_BYTES

public static final int SHORT_BYTES
See Also:
Constant Field Values

INT_BYTES

public static final int INT_BYTES
See Also:
Constant Field Values

LONG_BYTES

public static final int LONG_BYTES
See Also:
Constant Field Values

UNSIGNED_INT_BYTES

public static final int UNSIGNED_INT_BYTES
See Also:
Constant Field Values

ZERO_LENGTH_BYTE_ARRAY

public static final byte[] ZERO_LENGTH_BYTE_ARRAY
Constructor Detail

LogUtils

public LogUtils()
Method Detail

writeUnsignedInt

public static void writeUnsignedInt(ByteBuffer buf,
                                    long value)
Marshall a long into the next 4 bytes in this buffer. Necessary when the long is used to hold an unsigned int.


readUnsignedInt

public static long readUnsignedInt(ByteBuffer buf)
Unmarshall the next four bytes which hold an unsigned int into a long.


writeShort

public static void writeShort(ByteBuffer logBuf,
                              short i)
Write a short into the log.


readShort

public static short readShort(ByteBuffer logBuf)
Read a short from the log.


readInt

public static int readInt(ByteBuffer logBuf,
                          boolean unpacked)
Read an int from the log in either packed or unpacked format.


writeInt

public static void writeInt(ByteBuffer logBuf,
                            int i)
Write an int into the log.


readInt

public static int readInt(ByteBuffer logBuf)
Read a int from the log.


getIntLogSize

public static int getIntLogSize()
Returns:
log storage size for an int.

writePackedInt

public static void writePackedInt(ByteBuffer logBuf,
                                  int i)
Write a packed int into the log.


readPackedInt

public static int readPackedInt(ByteBuffer logBuf)
Read a packed int from the log.


getPackedIntLogSize

public static int getPackedIntLogSize(int i)
Returns:
log storage size for a packed int.

writeIntMSB

public static void writeIntMSB(ByteBuffer logBuf,
                               int i)
Write an int into the log in MSB order. Used for ordered keys.


readIntMSB

public static int readIntMSB(ByteBuffer logBuf)
Read a int from the log in MSB order. Used for ordered keys.


writeLong

public static void writeLong(ByteBuffer logBuf,
                             long l)
Write a long into the log.


readLong

public static long readLong(ByteBuffer logBuf,
                            boolean unpacked)
Read an int from the log in either packed or unpacked format.


readLong

public static long readLong(ByteBuffer logBuf)
Read a long from the log.


getLongLogSize

public static int getLongLogSize()
Returns:
log storage size for a long.

writePackedLong

public static void writePackedLong(ByteBuffer logBuf,
                                   long l)
Write a packed long into the log.


readPackedLong

public static long readPackedLong(ByteBuffer logBuf)
Read a packed long from the log.


getPackedLongLogSize

public static int getPackedLongLogSize(long l)
Returns:
log storage size for a packed long.

writeByteArray

public static void writeByteArray(ByteBuffer logBuf,
                                  byte[] b)
Write a byte array into the log. The size is stored first as an integer.


readByteArray

public static byte[] readByteArray(ByteBuffer logBuf,
                                   boolean unpacked)
Read a byte array from the log. The size is stored first as an integer.


getByteArrayLogSize

public static int getByteArrayLogSize(byte[] b)
Returns:
log storage size for a byteArray

writeBytesNoLength

public static void writeBytesNoLength(ByteBuffer logBuf,
                                      byte[] b)
Write a byte array into the log. No size is stored.


readBytesNoLength

public static byte[] readBytesNoLength(ByteBuffer logBuf,
                                       int size)
Read a byte array from the log. The size is not stored.


writeString

public static void writeString(ByteBuffer logBuf,
                               String stringVal)
Write a string into the log. The size is stored first as an integer.


readString

public static String readString(ByteBuffer logBuf,
                                boolean unpacked)
Read a string from the log. The size is stored first as an integer.


getStringLogSize

public static int getStringLogSize(String s)
Returns:
log storage size for a string

writeTimestamp

public static void writeTimestamp(ByteBuffer logBuf,
                                  Timestamp time)
Write a timestamp into the log.


readTimestamp

public static Timestamp readTimestamp(ByteBuffer logBuf,
                                      boolean unpacked)
Read a timestamp from the log.


getTimestampLogSize

public static int getTimestampLogSize(Timestamp time)
Returns:
log storage size for a timestamp

writeBoolean

public static void writeBoolean(ByteBuffer logBuf,
                                boolean bool)
Write a boolean into the log.


readBoolean

public static boolean readBoolean(ByteBuffer logBuf)
Read a boolean from the log.


getBooleanLogSize

public static int getBooleanLogSize()
Returns:
log storage size for a boolean.

dumpBoolean

public static boolean dumpBoolean(ByteBuffer itemBuffer,
                                  StringBuilder sb,
                                  String tag)

getXidSize

public static int getXidSize(Xid xid)
The byte[]'s in Xid's are known to be 255 or less in length. So instead of using read/writeByteArray(), we can save 6 bytes per record by making the byte[] length be 1 byte instead of 4.


writeXid

public static void writeXid(ByteBuffer logBuf,
                            Xid xid)

readXid

public static Xid readXid(ByteBuffer logBuf)


Copyright (c) 2004-2010 Oracle. All rights reserved.