org.opends.server.backends.jeb
Class JebFormat

java.lang.Object
  extended by org.opends.server.backends.jeb.JebFormat

public class JebFormat
extends java.lang.Object

Handles the disk representation of LDAP data.


Field Summary
static byte FORMAT_VERSION
          The format version used by this class to encode and decode a DatabaseEntry.
static byte TAG_DATABASE_ENTRY
          The ASN1 tag for the DatabaseEntry type.
static byte TAG_DIRECTORY_SERVER_ENTRY
          The ASN1 tag for the DirectoryServerEntry type.
 
Constructor Summary
JebFormat()
           
 
Method Summary
static byte[] decodeDatabaseEntry(byte[] bytes)
          Decode a DatabaseEntry.
static byte[] encodeDatabaseEntry(byte[] bytes, DataConfig dataConfig)
          Encodes a DatabaseEntry.
static Entry entryFromDatabase(byte[] bytes, CompressedSchema compressedSchema)
          Decodes an entry from its database representation.
static long entryIDFromDatabase(byte[] bytes)
          Decode an entry ID value from its database representation.
static long[] entryIDListFromDatabase(byte[] bytes)
          Decode an array of entry ID values from its database representation.
static byte[] entryIDListToDatabase(long[] entryIDArray)
          Encode an array of entry ID values to its database representation.
static byte[] entryIDToDatabase(long id)
          Encode an entry ID value to its database representation.
static long entryIDUndefinedSizeFromDatabase(byte[] bytes)
          Decode an entry ID count from its database representation.
static byte[] entryIDUndefinedSizeToDatabase(long count)
          Encode an entry ID set count to its database representation.
static byte[] entryToDatabase(Entry entry)
          Encodes an entry to the raw database format, without compression.
static byte[] entryToDatabase(Entry entry, DataConfig dataConfig)
          Encodes an entry to the raw database format, with optional compression.
static byte getEntryVersion(byte[] bytes)
          Get the version number of the DatabaseEntry.
static int[] intArrayFromDatabaseBytes(byte[] bytes)
          Decode a integer array using the specified byte array read from DB.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_VERSION

public static final byte FORMAT_VERSION
The format version used by this class to encode and decode a DatabaseEntry.

See Also:
Constant Field Values

TAG_DATABASE_ENTRY

public static final byte TAG_DATABASE_ENTRY
The ASN1 tag for the DatabaseEntry type.

See Also:
Constant Field Values

TAG_DIRECTORY_SERVER_ENTRY

public static final byte TAG_DIRECTORY_SERVER_ENTRY
The ASN1 tag for the DirectoryServerEntry type.

See Also:
Constant Field Values
Constructor Detail

JebFormat

public JebFormat()
Method Detail

decodeDatabaseEntry

public static byte[] decodeDatabaseEntry(byte[] bytes)
                                  throws ASN1Exception,
                                         java.util.zip.DataFormatException
Decode a DatabaseEntry. The encoded bytes may be compressed and/or encrypted.

Parameters:
bytes - The encoded bytes of a DatabaseEntry.
Returns:
The decoded bytes.
Throws:
ASN1Exception - If the data is not in the expected ASN.1 encoding format.
java.util.zip.DataFormatException - If an error occurs while trying to decompress compressed data.

entryFromDatabase

public static Entry entryFromDatabase(byte[] bytes,
                                      CompressedSchema compressedSchema)
                               throws DirectoryException,
                                      ASN1Exception,
                                      LDAPException,
                                      java.util.zip.DataFormatException
Decodes an entry from its database representation.

An entry on disk is ASN1 encoded in this format:

 DatabaseEntry ::= [APPLICATION 0] IMPLICIT SEQUENCE {
  uncompressedSize      INTEGER,      -- A zero value means not compressed.
  dataBytes             OCTET STRING  -- Optionally compressed encoding of
                                         the data bytes.
 }

 ID2EntryValue ::= DatabaseEntry
  -- Where dataBytes contains an encoding of DirectoryServerEntry.

 DirectoryServerEntry ::= [APPLICATION 1] IMPLICIT SEQUENCE {
  dn                      LDAPDN,
  objectClasses           SET OF LDAPString,
  userAttributes          AttributeList,
  operationalAttributes   AttributeList
 }
 

Parameters:
bytes - A byte array containing the encoded database value.
compressedSchema - The compressed schema manager to use when decoding.
Returns:
The decoded entry.
Throws:
ASN1Exception - If the data is not in the expected ASN.1 encoding format.
LDAPException - If the data is not in the expected ASN.1 encoding format.
java.util.zip.DataFormatException - If an error occurs while trying to decompress compressed data.
DirectoryException - If a Directory Server error occurs.

encodeDatabaseEntry

public static byte[] encodeDatabaseEntry(byte[] bytes,
                                         DataConfig dataConfig)
Encodes a DatabaseEntry. The encoded bytes may be compressed and/or encrypted.

Parameters:
bytes - The bytes to encode.
dataConfig - Compression and cryptographic options.
Returns:
A byte array containing the encoded DatabaseEntry.

entryToDatabase

public static byte[] entryToDatabase(Entry entry,
                                     DataConfig dataConfig)
                              throws DirectoryException
Encodes an entry to the raw database format, with optional compression.

Parameters:
entry - The entry to encode.
dataConfig - Compression and cryptographic options.
Returns:
A byte array containing the encoded database value.
Throws:
DirectoryException - If a problem occurs while attempting to encode the entry.

entryToDatabase

public static byte[] entryToDatabase(Entry entry)
                              throws DirectoryException
Encodes an entry to the raw database format, without compression.

Parameters:
entry - The entry to encode.
Returns:
A byte array containing the encoded database value.
Throws:
DirectoryException - If a problem occurs while attempting to encode the entry.

entryIDFromDatabase

public static long entryIDFromDatabase(byte[] bytes)
Decode an entry ID value from its database representation. Note that this method will throw an ArrayIndexOutOfBoundsException if the bytes array length is less than 8.

Parameters:
bytes - The database value of the entry ID.
Returns:
The entry ID value.

entryIDUndefinedSizeFromDatabase

public static long entryIDUndefinedSizeFromDatabase(byte[] bytes)
Decode an entry ID count from its database representation.

Parameters:
bytes - The database value of the entry ID count.
Returns:
The entry ID count.

entryIDListFromDatabase

public static long[] entryIDListFromDatabase(byte[] bytes)
Decode an array of entry ID values from its database representation.

Parameters:
bytes - The raw database value, null if there is no value and hence no entry IDs. Note that this method will throw an ArrayIndexOutOfBoundsException if the bytes array length is not a multiple of 8.
Returns:
An array of entry ID values.

intArrayFromDatabaseBytes

public static int[] intArrayFromDatabaseBytes(byte[] bytes)
Decode a integer array using the specified byte array read from DB.

Parameters:
bytes - The byte array.
Returns:
An integer array.

entryIDToDatabase

public static byte[] entryIDToDatabase(long id)
Encode an entry ID value to its database representation.

Parameters:
id - The entry ID value to be encoded.
Returns:
The encoded database value of the entry ID.

entryIDUndefinedSizeToDatabase

public static byte[] entryIDUndefinedSizeToDatabase(long count)
Encode an entry ID set count to its database representation.

Parameters:
count - The entry ID set count to be encoded.
Returns:
The encoded database value of the entry ID.

entryIDListToDatabase

public static byte[] entryIDListToDatabase(long[] entryIDArray)
Encode an array of entry ID values to its database representation.

Parameters:
entryIDArray - An array of entry ID values.
Returns:
The encoded database value.

getEntryVersion

public static byte getEntryVersion(byte[] bytes)
Get the version number of the DatabaseEntry.

Parameters:
bytes - The encoded bytes of a DatabaseEntry.
Returns:
The version number.