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 fromdata
.RString(java.nio.ByteBuffer buf, int length)
Create an RString from the firstlength
bytes ofbuf
.RString(java.lang.String value)
Create an rstring set fromvalue
using UTF-8 encoding.
-
Method Summary
Methods Modifier and Type Method and Description boolean
equals(java.lang.Object other)
Compares this toother
.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 thisRString
.java.nio.ByteBuffer
put(java.nio.ByteBuffer buf)
Put this value into a byte buffer.java.lang.String
toString()
Returns getString().
-
-
-
Field Detail
-
IBM_COPYRIGHT
public static final java.lang.String IBM_COPYRIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RString
public RString(java.nio.ByteBuffer buf, int length)
Create an RString from the firstlength
bytes ofbuf
.- Parameters:
buf
- ByteBuffer to read value from.length
- Number of bytes to read.
-
RString
public RString(byte[] data)
Create an rstring set fromdata
. 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 fromvalue
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 thisRString
. Equivalent tojava.util.Arrays.hashCode(getData())
.- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
Compares this toother
. The result is true if and only ifother
is an instance ofRString
containing the exact same sequence of bytes asthis
.- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
Returns getString().- Overrides:
toString
in classjava.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.
-
-