Class InetAddressEncoding

java.lang.Object
io.permazen.encoding.AbstractEncoding<T>
io.permazen.encoding.InetAddressEncoding
All Implemented Interfaces:
Encoding<InetAddress>, NaturalSortAware, Serializable, Comparator<InetAddress>

public class InetAddressEncoding extends AbstractEncoding<T>
Non-null InetAddress type. Null values are not supported by this class.

Binary encoding uses the binary value from InetAddress.getAddress(), preceded by 0x04 for IPv4 or 0x06 for IPv6.

See Also:
  • Constructor Details

    • InetAddressEncoding

      public InetAddressEncoding(EncodingId encodingId)
  • Method Details

    • withEncodingId

      public InetAddressEncoding withEncodingId(EncodingId encodingId)
      Description copied from interface: Encoding
      Build an encoding that has the given EncodingId but is otherwise equivalent to this encoding.

      If this encoding already has encodingId, then this method may (but is not required to) return this same instance.

      Parameters:
      encodingId - new encoding's EncodingId, or null for an anonymized encoding
      Returns:
      a version of this encoding with the given EncodingId
    • hasPrefix0x00

      public boolean hasPrefix0x00()
      Description copied from interface: Encoding
      Determine whether any of this encoding's encoded values start with a 0x00 byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.

      Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.

      The implementation in Encoding returns true.

      Returns:
      true if an encoded value starting with 0x00 exists
    • hasPrefix0xff

      public boolean hasPrefix0xff()
      Description copied from interface: Encoding
      Determine whether any of this encoding's encoded values start with a 0xff byte. Certain optimizations are possible when this is not the case. It is safe for this method to always return true.

      Note: changing the result of this method may result in an incompatible encoding if this encoding is wrapped in another class.

      The implementation in Encoding returns true.

      Returns:
      true if an encoded value starting with 0xff exists
    • getLength

      protected int getLength(ByteReader reader)
    • write

      public void write(ByteWriter writer, InetAddress addr)
      Description copied from interface: Encoding
      Write a value to the given output.
      Specified by:
      write in interface Encoding<InetAddress>
      Parameters:
      writer - byte output
      addr - value to write (possibly null)
    • read

      public InetAddress read(ByteReader reader)
      Description copied from interface: Encoding
      Read a value from the given input.
      Parameters:
      reader - byte input
      Returns:
      field value (possibly null)
    • skip

      public void skip(ByteReader reader)
      Description copied from interface: Encoding
      Read and discard a byte[] encoded value from the given input.
      Parameters:
      reader - byte input
    • toString

      public String toString(InetAddress addr)
      Description copied from interface: Encoding
      Encode a non-null value as a String for later decoding by fromString().

      Each of the characters in the returned String must be one of the valid XML characters (tab, newline, carriage return, \u0020 - \ud7ff, and \ue000 - \ufffd).

      Parameters:
      addr - actual value, never null
      Returns:
      string encoding of value acceptable to fromString()
      See Also:
    • fromString

      public InetAddress fromString(String string)
      Description copied from interface: Encoding
      Parse a non-null value previously encoded by toString(T).
      Parameters:
      string - non-null value previously encoded as a String by toString(T)
      Returns:
      actual value
    • compare

      public int compare(InetAddress addr1, InetAddress addr2)
      Description copied from interface: Encoding
      Order two field values.

      This method must provide a total ordering of all supported Java values that is consistent with the database ordering, i.e., the unsigned lexicographical ordering of the corresponding byte[] encoded field values.

      If null is a supported Java value, then the this method must accept null parameters without throwing an exception (note, this is a stronger requirement than the Comparator interface normally requires).

      Note: by convention, null values usually sort last.