com.ibm.streams.operator.types

Class RString

  • java.lang.Object
    • com.ibm.streams.operator.types.RString
  • All Implemented Interfaces:
    java.io.Serializable


    public final class RString
    extends java.lang.Object
    implements java.io.Serializable
    SPL rstring. An rstring represents a sequence of raw bytes, typically used for simple string representations with ASCII or UTF-8 encoding. RString is an immutable object.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String IBM_COPYRIGHT 
    • Constructor Summary

      Constructors 
      Constructor and Description
      RString(byte[] data)
      Create an rstring set from data.
      RString(java.nio.ByteBuffer buf, int length)
      Create an RString from the first length bytes of buf.
      RString(java.lang.String value)
      Create an rstring set from value using UTF-8 encoding.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean equals(java.lang.Object other)
      Compares this to other.
      java.nio.ByteBuffer getByteBuffer()
      Get a ByteBuffer that represents the contents of this value.
      byte[] getData()
      Get the raw data for this value.
      int getLength()
      Get the number of bytes in the rstring value.
      java.lang.String getString()
      Return the value as a String using UTF-8 encoding.
      java.lang.String getString(java.nio.charset.Charset charset)
      Return the value as a String using the defined character set encoding.
      java.lang.String getString(java.lang.String charsetName)
      Return the value as a String using the defined character set encoding.
      int hashCode()
      Returns a hash code for this RString.
      java.nio.ByteBuffer put(java.nio.ByteBuffer buf)
      Put this value into a byte buffer.
      java.lang.String toString()
      Returns getString().
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RString

        public RString(java.nio.ByteBuffer buf,
               int length)
        Create an RString from the first length bytes of buf.
        Parameters:
        buf - ByteBuffer to read value from.
        length - Number of bytes to read.
      • RString

        public RString(byte[] data)
        Create an rstring set from data. A copy of the passed in byte array is made.
        Parameters:
        data - Byte array to clone as the value.
      • RString

        public RString(java.lang.String value)
        Create an rstring set from value using UTF-8 encoding.
        Parameters:
        value - Value used to initialize this.
    • Method Detail

      • getLength

        public int getLength()
        Get the number of bytes in the rstring value.
        Returns:
        Number of bytes in this rstring
      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer()
        Get a ByteBuffer that represents the contents of this value.
        Returns:
        A ByteBuffer positioned at the first byte.
      • getData

        public byte[] getData()
        Get the raw data for this value.
        Returns:
        A copy of the raw data for this value.
      • getString

        public java.lang.String getString()
        Return the value as a String using UTF-8 encoding.
        Returns:
        Value as a String.
      • getString

        public java.lang.String getString(java.lang.String charsetName)
                                   throws java.io.IOException
        Return the value as a String using the defined character set encoding.
        Returns:
        Value as a String.
        Throws:
        java.io.IOException
      • getString

        public java.lang.String getString(java.nio.charset.Charset charset)
        Return the value as a String using the defined character set encoding.
        Returns:
        Value as a String.
      • hashCode

        public int hashCode()
        Returns a hash code for this RString. Equivalent to java.util.Arrays.hashCode(getData()).
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals(java.lang.Object other)
        Compares this to other. The result is true if and only if other is an instance of RString containing the exact same sequence of bytes as this.
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns getString().
        Overrides:
        toString in class java.lang.Object
      • put

        public java.nio.ByteBuffer put(java.nio.ByteBuffer buf)
        Put this value into a byte buffer. Will write the raw bytes representing this value.
        Parameters:
        buf - ByteBuffer to be written into.
        Returns:
        The passed in ByteBuffer.