org.apache.directory.mavibot.btree.serializer

## Class StringSerializer

- java.lang.Object
- - org.apache.directory.mavibot.btree.serializer.AbstractElementSerializer<String>
  - - org.apache.directory.mavibot.btree.serializer.StringSerializer

- All Implemented Interfaces:
    ElementSerializer<String>

      public class StringSerializer
      extends AbstractElementSerializer<String>

  The String serializer.
  Author:
    Apache Directory Project

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static StringSerializer` | `INSTANCE` A static instance of a StringSerializer

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringSerializer(Comparator<String> comparator)` Create a new instance of StringSerializer with custom comparator

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(String type1, String type2)` Returns the comparison of two types.
    `String` | `deserialize(BufferHandler bufferHandler)` Deserialize an element from a BufferHandler
    `static String` | `deserialize(byte[] in)` A static method used to deserialize a String from a byte array.
    `static String` | `deserialize(byte[] in, int start)` A static method used to deserialize a String from a byte array.
    `String` | `deserialize(ByteBuffer buffer)` Deserialize an element from a ByteBuffer
    `String` | `fromBytes(byte[] in)` A method used to deserialize a String from a byte array.
    `String` | `fromBytes(byte[] in, int start)` A method used to deserialize a String from a byte array.
    `static byte[]` | `serialize(byte[] buffer, int start, String element)` Serialize a String.
    `byte[]` | `serialize(String element)` Produce the byte[] representation of the element

    - ### Methods inherited from class org.apache.directory.mavibot.btree.serializer.AbstractElementSerializer

      `getComparator, getType`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### INSTANCE

          public static final StringSerializer INSTANCE

      A static instance of a StringSerializer

  - ### Constructor Detail

    - #### StringSerializer

          public StringSerializer(Comparator<String> comparator)

      Create a new instance of StringSerializer with custom comparator

  - ### Method Detail

    - #### deserialize

          public static String deserialize(byte[] in)

      A static method used to deserialize a String from a byte array.
      Parameters:
        `in` - The byte array containing the String
      Returns:
        A String

    - #### deserialize

          public static String deserialize(byte[] in,
                           int start)

      A static method used to deserialize a String from a byte array.
      Parameters:
        `in` - The byte array containing the String
      Returns:
        A String

    - #### fromBytes

          public String fromBytes(byte[] in)

      A method used to deserialize a String from a byte array.
      Parameters:
        `in` - The byte array containing the String
      Returns:
        A String

    - #### fromBytes

          public String fromBytes(byte[] in,
                         int start)

      A method used to deserialize a String from a byte array.
      Parameters:
        `in` - The byte array containing the String
      Returns:
        A String

    - #### serialize

          public static byte[] serialize(byte[] buffer,
                         int start,
                         String element)

      Serialize a String. We store the length on 4 bytes, then the String
      Parameters:
        `buffer` - the Buffer that will contain the serialized value
        `start` - the position in the buffer we will store the serialized String
        `value` - the value to serialize
      Returns:
        The byte[] containing the serialized String

    - #### serialize

          public byte[] serialize(String element)

      Produce the byte[] representation of the element
      Parameters:
        `element` - The element to serialize
      Returns:
        The byte[] containing the serialized element

    - #### deserialize

          public String deserialize(BufferHandler bufferHandler)
                             throws IOException

      Deserialize an element from a BufferHandler
      Parameters:
        `bufferHandler` - The incoming bufferHandler
      Returns:
        The deserialized element
      Throws:
        `IOException`

    - #### deserialize

          public String deserialize(ByteBuffer buffer)
                             throws IOException

      Deserialize an element from a ByteBuffer
      Parameters:
        `buffer` - The incoming ByteBuffer
      Returns:
        The deserialized element
      Throws:
        `IOException` - If the deserialization failed

    - #### compare

          public int compare(String type1,
                    String type2)

      Returns the comparison of two types.
      - If type1 < type2, return -1
      - If type1 > type2, return 1
      - If type1 == type2, return 0
      Specified by:
        `compare` in interface `ElementSerializer<String>`
      Overrides:
        `compare` in class `AbstractElementSerializer<String>`
      Parameters:
        `type1` - The first type to compare
        `type2` - The second type to compare
      Returns:
        The comparison result

Copyright © 2012–2015 Apache Mavibot Project Parent. All rights reserved.