Class KeyDescription

java.lang.Object
com.basis.filesystem.util.KeyDescription
All Implemented Interfaces:
Serializable, Cloneable

public class KeyDescription extends Object implements Cloneable, Serializable
Class used to describe derived keys in MKEYED and XKEYED files.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
    Deprecated.
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    KeyDescription(int p_keyNum, byte[] p_data, int p_offset, int p_end)
    Constructor from a byte array in FIN format.
    KeyDescription(int p_keyNum, byte[] p_data, int p_offset, int p_end, boolean p_extended)
    Constructor from a byte array in FIN or XFIN format.
    KeyDescription(List<KeySegment> p_segments, boolean p_unique)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkSegments(int p_errorCode)
     
    void
    checkSegments(String p_filename, int p_errorCode)
    Helper function to check and make sure that segments are valid for an MKEYED file.
     
    boolean
    equals(Object p_other)
     
    final void
    fixDescendingSegments(byte[] p_fromKey, int p_fromKeyLen, byte[] p_toKey, int p_toKeyLen, boolean p_mangle)
    Fix descending segments so that they are switched to/from normal.
    final void
    fixDescendingSegments(byte[] p_fromKey, int p_fromOffset, int p_fromKeyLen, byte[] p_toKey, int p_toOffset, int p_toKeyLen, boolean p_mangle)
    Fix descending segments so that they are switched to/from normal.
    final void
    fixDescendingSegments(byte[] p_fromKey, int p_fromOffset, int p_fromKeyLen, byte[] p_toKey, int p_toOffset, int p_toKeyLen, Locale p_locale, Charset p_charset, boolean p_mangle)
    Fix descending segments so that they are switched to/from normal.
    final void
    fixDescendingSegments(io.netty.buffer.ByteBuf p_fromKey, io.netty.buffer.ByteBuf p_toKey, Locale p_locale, Charset p_charset, boolean p_mangle)
    Fix descending segments so that they are switched to/from normal.
    final void
    getAndFixKeyForRecord(io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Locale p_locale, Charset p_charset, boolean p_mangle)
     
    final void
    getAndFixKeyForRecord(String p_filename, io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Locale p_locale, Charset p_charset, boolean p_mangle)
     
    getKeyDescriptions(byte[] p_data, int p_offset, int p_end)
     
    getKeyDescriptions(String p_filename, byte[] p_data, int p_offset, int p_end)
    Helper function to pull a list of KeyDescription objects out of a byte array.
    static int
    Return number of bytes needed to encode an array of KeyDescription objects in FIN format.
    static int
    Return number of bytes needed to encode a list of KeyDescription objects in FIN format.
    final void
    getKeyForRecord(byte[] p_record, int p_size, byte[] p_key)
     
    final void
    getKeyForRecord(byte[] p_record, int p_size, byte[] p_key, boolean p_checkFields)
     
    final void
    getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength)
     
    final void
    getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields)
     
    final void
    getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset)
     
    final void
    getKeyForRecord(byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields)
     
    final void
    getKeyForRecord(byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset)
     
    final void
    getKeyForRecord(io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Charset p_charset)
     
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_size, byte[] p_key)
    Get the derived key value for a record.
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_size, byte[] p_key, boolean p_checkFields)
    Get the derived key value for a record.
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength)
    Get the derived key value for a record.
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields)
    Get the derived key value for a record.
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset)
    Get the derived key value for a record.
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields)
     
    final void
    getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset)
     
    final void
    getKeyForRecord(String p_filename, io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Charset p_charset)
     
    Get list of key segments (copy of internal list).
    int
    Get the key size (sum of lengths of the segments).
    getXKeyDescriptions(byte[] p_data, int p_offset, int p_end)
     
    getXKeyDescriptions(String p_filename, byte[] p_data, int p_offset, int p_end)
    Helper function to pull a list of KeyDescription objects out of a byte array in XFIN format.
    static int
    Return number of bytes needed to encode a list of KeyDescription objects in XFIN format.
    static int
    Return number of bytes needed to encode an array of KeyDescription objects in XFIN format.
    static int
    Return number of bytes needed to encode a list of KeyDescription objects in XFIN format.
    int
     
    boolean
    hasSpecialType(int p_special)
    Helper method to see if any of the segments have a given special type.
    boolean
    Is the last key segment fielded?
    boolean
    Get whether this key is unique.
    static int
    putKeyDescriptions(KeyDescription[] p_keyDesc, byte[] p_data, int p_offset, int p_length)
    Helper function to put KeyDescription objects into a byte array.
    static int
    putKeyDescriptions(List<KeyDescription> p_keyDesc, byte[] p_data, int p_offset, int p_length)
    Helper function to put KeyDescription objects into a byte array.
    static int
    putXKeyDescriptions(KeyDescription[] p_keyDesc, byte[] p_data, int p_offset, int p_length)
    Helper function to put KeyDescription objects into a byte array.
    static int
    putXKeyDescriptions(KeyDescription p_keyDesc, byte[] p_data, int p_offset, int p_length)
    Helper function to put KeyDescription objects into a byte array.
    static int
    putXKeyDescriptions(List<KeyDescription> p_keyDesc, byte[] p_data, int p_offset, int p_length)
    Helper function to put KeyDescription objects into a byte array.
    void
    setUnique(boolean p_unique)
    Set that this key is unique.
     

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • KeyDescription

      public KeyDescription()
    • KeyDescription

      public KeyDescription(List<KeySegment> p_segments, boolean p_unique) throws FilesystemException
      Constructor
      Parameters:
      p_segments - List of KeySegment objects describing the segments of this key.
      p_unique - true if the key is unique.
      Throws:
      FilesystemException - If a filesystem problem occurs.
    • KeyDescription

      public KeyDescription(int p_keyNum, byte[] p_data, int p_offset, int p_end) throws FilesystemException
      Constructor from a byte array in FIN format.
      Parameters:
      p_keyNum - Key number to extract from the buffer.
      p_data - Buffer with the key information.
      p_offset - Offset in the buffer to start extracting.
      p_end - End of the buffer to extract keys.
      Throws:
      FilesystemException - If a filesystem problem occurs.
    • KeyDescription

      public KeyDescription(int p_keyNum, byte[] p_data, int p_offset, int p_end, boolean p_extended) throws FilesystemException
      Constructor from a byte array in FIN or XFIN format.
      Parameters:
      p_keyNum - Key number to extract from the buffer.
      p_data - Buffer with the key information.
      p_offset - Offset in the buffer to start extracting.
      p_end - End of the buffer to extract keys.
      p_extended - true if the byte array is in XFIN format.
      Throws:
      FilesystemException - If a filesystem problem occurs.
  • Method Details

    • equals

      public boolean equals(Object p_other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isLastSegmentFielded

      public boolean isLastSegmentFielded()
      Is the last key segment fielded?
    • hasSpecialType

      public boolean hasSpecialType(int p_special)
      Helper method to see if any of the segments have a given special type.
      Parameters:
      p_special - Special type to look for.
      Returns:
      True if a segment in this key has the special type provided.
    • checkSegments

      public void checkSegments(int p_errorCode) throws FilesystemException
      Throws:
      FilesystemException
    • checkSegments

      public void checkSegments(String p_filename, int p_errorCode) throws FilesystemException
      Helper function to check and make sure that segments are valid for an MKEYED file.
      Parameters:
      p_filename -
      p_errorCode - Error code to use for violations.
      Throws:
      FilesystemException - If a filesystem problem occurs.
    • getKeySize

      public int getKeySize()
      Get the key size (sum of lengths of the segments).
      Returns:
      Actual size of this key.
    • setUnique

      public void setUnique(boolean p_unique)
      Set that this key is unique.
      Parameters:
      p_unique - Is this key unique?
    • isUnique

      public boolean isUnique()
      Get whether this key is unique.
      Returns:
      true if the key is unique.
    • getKeySegments

      public List<KeySegment> getKeySegments()
      Get list of key segments (copy of internal list).
      Returns:
      List of the key segments for this key.
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_size, byte[] p_key) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_size, byte[] p_key) throws FilesystemException
      Get the derived key value for a record.
      Parameters:
      p_filename -
      p_record - Record to derive key for.
      p_size - Size of the record.
      p_key - Buffer to fill with the key value.
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_size, byte[] p_key, boolean p_checkFields) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_size, byte[] p_key, boolean p_checkFields) throws FilesystemException
      Get the derived key value for a record.
      Parameters:
      p_filename -
      p_record - Record to derive key for.
      p_size - Size of the record.
      p_key - Buffer to fill with the key value.
      p_checkFields - Should field existence be enforced?
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength) throws FilesystemException
      Get the derived key value for a record.
      Parameters:
      p_filename -
      p_record - Record to derive key for.
      p_roffset - Record offset.
      p_size - Size of the record.
      p_key - Buffer to fill with the key value.
      p_koffset - Key offset.
      p_klength - Key Length.
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields) throws FilesystemException
      Get the derived key value for a record.
      Parameters:
      p_filename -
      p_record - Record to derive key for.
      p_roffset - Record offset.
      p_size - Size of the record.
      p_key - Buffer to fill with the key value.
      p_koffset - Key offset.
      p_klength - Key Length.
      p_checkFields - Should field existence be enforced?
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Get the derived key value for a record.
      Parameters:
      p_filename -
      p_record - Record to derive key for.
      p_roffset - Record offset.
      p_size - Size of the record.
      p_key - Buffer to fill with the key value.
      p_koffset - Key offset.
      p_klength - Key Length.
      p_checkFields - Should field existence be enforced?
      p_charset - Charset for decoding/encoding strings.
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, byte[] p_record, int p_roffset, int p_size, int p_actualRecordSize, byte[] p_key, int p_koffset, int p_klength, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyForRecord

      public final void getKeyForRecord(String p_filename, io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Charset p_charset) throws FilesystemException
      Throws:
      FilesystemException
    • getAndFixKeyForRecord

      public final void getAndFixKeyForRecord(io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Locale p_locale, Charset p_charset, boolean p_mangle) throws FilesystemException
      Throws:
      FilesystemException
    • getAndFixKeyForRecord

      public final void getAndFixKeyForRecord(String p_filename, io.netty.buffer.ByteBuf p_record, int p_actualRecordSize, io.netty.buffer.ByteBuf p_key, boolean p_checkFields, Locale p_locale, Charset p_charset, boolean p_mangle) throws FilesystemException
      Throws:
      FilesystemException
    • fixDescendingSegments

      public final void fixDescendingSegments(byte[] p_fromKey, int p_fromKeyLen, byte[] p_toKey, int p_toKeyLen, boolean p_mangle)
      Fix descending segments so that they are switched to/from normal.
      Parameters:
      p_fromKey - Key to convert.
      p_fromKeyLen - Length of the key to convert.
      p_toKey - Key buffer to fill.
      p_toKeyLen - Length of the key buffer to fill.
      p_mangle - true if numeric fields should be adjusted for descending.
    • fixDescendingSegments

      public final void fixDescendingSegments(byte[] p_fromKey, int p_fromOffset, int p_fromKeyLen, byte[] p_toKey, int p_toOffset, int p_toKeyLen, boolean p_mangle)
      Fix descending segments so that they are switched to/from normal.
      Parameters:
      p_fromKey - Key to convert.
      p_fromOffset - Starting offset.
      p_fromKeyLen - Length of the key to convert.
      p_toKey - Key buffer to fill.
      p_toOffset - Starting offset.
      p_toKeyLen - Length of the key buffer to fill.
      p_mangle - true if numeric fields should be adjusted for descending.
    • fixDescendingSegments

      public final void fixDescendingSegments(byte[] p_fromKey, int p_fromOffset, int p_fromKeyLen, byte[] p_toKey, int p_toOffset, int p_toKeyLen, Locale p_locale, Charset p_charset, boolean p_mangle)
      Fix descending segments so that they are switched to/from normal.
      Parameters:
      p_fromKey - Key to convert.
      p_fromOffset - Starting offset.
      p_fromKeyLen - Length of the key to convert.
      p_toKey - Key buffer to fill.
      p_toOffset - Starting offset.
      p_toKeyLen - Length of the key buffer to fill.
      p_locale - Locale for case insensitive segments.
      p_charset - Charset for decoding/encoding strings
      p_mangle - true if numeric fields should be adjusted for descending.
    • fixDescendingSegments

      public final void fixDescendingSegments(io.netty.buffer.ByteBuf p_fromKey, io.netty.buffer.ByteBuf p_toKey, Locale p_locale, Charset p_charset, boolean p_mangle)
      Fix descending segments so that they are switched to/from normal.
      Parameters:
      p_fromKey - Key to convert.
      p_toKey - Key buffer to fill.
      p_locale - Locale for case insensitive segments.
      p_charset - Charset for decoding/encoding strings
      p_mangle - true if numeric fields should be adjusted for descending.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public KeyDescription clone()
      Overrides:
      clone in class Object
    • getKeyDescriptions

      public static List<KeyDescription> getKeyDescriptions(byte[] p_data, int p_offset, int p_end) throws FilesystemException
      Throws:
      FilesystemException
    • getKeyDescriptions

      public static List<KeyDescription> getKeyDescriptions(String p_filename, byte[] p_data, int p_offset, int p_end) throws FilesystemException
      Helper function to pull a list of KeyDescription objects out of a byte array.
      Parameters:
      p_filename -
      p_data - Buffer with keys.
      p_offset - Offset in buffer to start looking for keys.
      p_end - End in the buffer to look for keys.
      Throws:
      FilesystemException - If a filesystem problem occurs.
    • getKeyDescriptionsSize

      public static int getKeyDescriptionsSize(KeyDescription[] p_keyDesc)
      Return number of bytes needed to encode an array of KeyDescription objects in FIN format.
      Parameters:
      p_keyDesc - Array of KeyDescription objects.
    • getKeyDescriptionsSize

      public static int getKeyDescriptionsSize(List<KeyDescription> p_keyDesc)
      Return number of bytes needed to encode a list of KeyDescription objects in FIN format.
      Parameters:
      p_keyDesc - List of KeyDescription objects.
    • putXKeyDescriptions

      public static int putXKeyDescriptions(KeyDescription[] p_keyDesc, byte[] p_data, int p_offset, int p_length)
      Helper function to put KeyDescription objects into a byte array.
      Parameters:
      p_keyDesc - Array of key descriptions.
      p_data - Buffer to put key information in.
      p_offset - Offset in the buffer to start placing key information.
      p_length - Length of the buffer that we are allowed to place key information in.
    • putXKeyDescriptions

      public static int putXKeyDescriptions(List<KeyDescription> p_keyDesc, byte[] p_data, int p_offset, int p_length)
      Helper function to put KeyDescription objects into a byte array.
      Parameters:
      p_keyDesc - List of key descriptions.
      p_data - Buffer to put key information in.
      p_offset - Offset in the buffer to start placing key information.
      p_length - Length of the buffer that we are allowed to place key information in.
    • putXKeyDescriptions

      public static int putXKeyDescriptions(KeyDescription p_keyDesc, byte[] p_data, int p_offset, int p_length)
      Helper function to put KeyDescription objects into a byte array.
      Parameters:
      p_keyDesc - List of key descriptions.
      p_data - Buffer to put key information in.
      p_offset - Offset in the buffer to start placing key information.
      p_length - Length of the buffer that we are allowed to place key information in.
    • getXKeyDescriptions

      public static List<KeyDescription> getXKeyDescriptions(byte[] p_data, int p_offset, int p_end) throws FilesystemException
      Throws:
      FilesystemException
    • getXKeyDescriptions

      public static List<KeyDescription> getXKeyDescriptions(String p_filename, byte[] p_data, int p_offset, int p_end) throws FilesystemException
      Helper function to pull a list of KeyDescription objects out of a byte array in XFIN format.
      Parameters:
      p_filename -
      p_data - Buffer with keys.
      p_offset - Offset in buffer to start looking for keys.
      p_end - End in the buffer to look for keys.
      Throws:
      FilesystemException - If a filesystem problem occurs.
    • getXKeyDescriptionsSize

      public static int getXKeyDescriptionsSize(KeyDescription[] p_keyDesc)
      Return number of bytes needed to encode an array of KeyDescription objects in XFIN format.
      Parameters:
      p_keyDesc - Array of KeyDescription objects.
    • getXKeyDescriptionsSize

      public static int getXKeyDescriptionsSize(List<KeyDescription> p_keyDesc)
      Return number of bytes needed to encode a list of KeyDescription objects in XFIN format.
      Parameters:
      p_keyDesc - List of KeyDescription objects.
    • getXKeyDescriptionsSize

      public static int getXKeyDescriptionsSize(KeyDescription p_keyDesc)
      Return number of bytes needed to encode a list of KeyDescription objects in XFIN format.
      Parameters:
      p_keyDesc - List of KeyDescription objects.
    • putKeyDescriptions

      public static int putKeyDescriptions(KeyDescription[] p_keyDesc, byte[] p_data, int p_offset, int p_length)
      Helper function to put KeyDescription objects into a byte array.
      Parameters:
      p_keyDesc - Array of key descriptions.
      p_data - Buffer to put key information in.
      p_offset - Offset in the buffer to start placing key information.
      p_length - Length of the buffer that we are allowed to place key information in.
    • putKeyDescriptions

      public static int putKeyDescriptions(List<KeyDescription> p_keyDesc, byte[] p_data, int p_offset, int p_length)
      Helper function to put KeyDescription objects into a byte array.
      Parameters:
      p_keyDesc - List of key descriptions.
      p_data - Buffer to put key information in.
      p_offset - Offset in the buffer to start placing key information.
      p_length - Length of the buffer that we are allowed to place key information in.