Class XdrString

java.lang.Object
org.stellar.sdk.xdr.XdrString
All Implemented Interfaces:
XdrElement

public final class XdrString extends Object implements XdrElement
Represents XDR string data.
  • Constructor Details

    • XdrString

      public XdrString(byte[] bytes)
      Creates an XdrString from raw bytes.
      Parameters:
      bytes - the string bytes
    • XdrString

      public XdrString(String text)
      Creates an XdrString from UTF-8 text.
      Parameters:
      text - the text value
  • Method Details

    • encode

      public void encode(XdrDataOutputStream stream) throws IOException
      Encodes this string to XDR.
      Specified by:
      encode in interface XdrElement
      Parameters:
      stream - the destination XDR output stream
      Throws:
      IOException - if an I/O error occurs while writing the value
    • decode

      public static XdrString decode(XdrDataInputStream stream, int maxDepth, int maxSize) throws IOException
      Decodes an XdrString from the provided stream.
      Parameters:
      stream - the source XDR input stream
      maxDepth - the maximum decoding depth, ignored for this leaf type
      maxSize - the maximum allowed string size in bytes
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the encoded size is invalid or an I/O error occurs
    • decode

      public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException
      Decodes an XdrString from the provided stream using the default maximum depth.
      Parameters:
      stream - the source XDR input stream
      maxSize - the maximum allowed string size in bytes
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the encoded size is invalid or an I/O error occurs
    • fromXdrBase64

      public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException
      Decodes an XdrString from a base64-encoded XDR string.
      Parameters:
      xdr - the base64-encoded XDR string
      maxSize - the maximum allowed string size in bytes
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the input is invalid or cannot be decoded
    • fromXdrBase64

      public static XdrString fromXdrBase64(String xdr) throws IOException
      Decodes an XdrString from a base64-encoded XDR string.
      Parameters:
      xdr - the base64-encoded XDR string
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the input is invalid or cannot be decoded
    • fromXdrByteArray

      public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException
      Decodes an XdrString from raw XDR bytes.
      Parameters:
      xdr - the raw XDR bytes
      maxSize - the maximum allowed string size in bytes
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the input is invalid or cannot be decoded
    • fromXdrByteArray

      public static XdrString fromXdrByteArray(byte[] xdr) throws IOException
      Decodes an XdrString from raw XDR bytes.
      Parameters:
      xdr - the raw XDR bytes
      Returns:
      the decoded XdrString
      Throws:
      IOException - if the input is invalid or cannot be decoded
    • toJson

      public String toJson()
      Serializes this value to JSON.
      Specified by:
      toJson in interface XdrElement
      Returns:
      the JSON representation of this string
    • fromJson

      public static XdrString fromJson(String json)
      Parses an XdrString from JSON.
      Parameters:
      json - the JSON representation
      Returns:
      the parsed XdrString, or null if the input is null
    • toString

      public String toString()
      Returns this value decoded as a UTF-8 string.
      Overrides:
      toString in class Object
      Returns:
      the UTF-8 string representation
    • getBytes

      public byte[] getBytes()
      Raw bytes of the XDR string value.
      Returns:
      the encoded string bytes
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object