XNIO API 3.0.4.GA

org.xnio
Class ByteString

java.lang.Object
  extended by org.xnio.ByteString
All Implemented Interfaces:
Serializable, Comparable<ByteString>

public final class ByteString
extends Object
implements Comparable<ByteString>, Serializable

An immutable string of bytes. Since instances of this class are guaranteed to be immutable, they are safe to use as Option values and in an OptionMap.

See Also:
Serialized Form

Method Summary
 int compareTo(ByteString o)
          Compare this ByteString to another.
static ByteString copyOf(byte[] b, int offs, int len)
          Create a byte string from the given array segment.
 boolean equals(ByteString other)
          Determine if this ByteString equals another ByteString.
 boolean equals(Object obj)
          Determine if this ByteString equals another ByteString.
 byte[] getBytes()
          Get a copy of the bytes of this ByteString.
 void getBytes(byte[] dest)
          Copy the bytes of this ByteString into the destination array.
 void getBytes(byte[] dest, int offs)
          Copy the bytes of this ByteString into the destination array.
 void getBytes(byte[] dest, int offs, int len)
          Copy the bytes of this ByteString into the destination array.
static ByteString getBytes(ByteBuffer buffer)
          Get a byte string from all remaining bytes of a ByteBuffer.
static ByteString getBytes(ByteBuffer buffer, int length)
          Get a byte string from a ByteBuffer.
static ByteString getBytes(String str, Charset charset)
          Get a byte string from the bytes of a character string.
static ByteString getBytes(String str, String charset)
          Get a byte string from the bytes of a character string.
 int hashCode()
          Get the hash code for this ByteString.
 int length()
          Get the number of bytes in this byte string.
static ByteString of(byte... bytes)
          Create a byte string of the given literal bytes.
 ByteString substring(int offs)
          Get the substring of this string starting at the given offset.
 ByteString substring(int offs, int len)
          Get the substring of this string starting at the given offset.
 String toString(String charset)
          Convert this byte string to a standard string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

of

public static ByteString of(byte... bytes)
Create a byte string of the given literal bytes. The given array is copied.

Parameters:
bytes - the bytes
Returns:
the byte string

copyOf

public static ByteString copyOf(byte[] b,
                                int offs,
                                int len)
Create a byte string from the given array segment.

Parameters:
b - the byte array
offs - the offset into the array
len - the number of bytes to copy
Returns:
the new byte string

getBytes

public static ByteString getBytes(String str,
                                  String charset)
                           throws UnsupportedEncodingException
Get a byte string from the bytes of a character string.

Parameters:
str - the character string
charset - the character set to use
Returns:
the byte string
Throws:
UnsupportedEncodingException - if the encoding is not supported

getBytes

public static ByteString getBytes(String str,
                                  Charset charset)
Get a byte string from the bytes of a character string.

Parameters:
str - the character string
charset - the character set to use
Returns:
the byte string

getBytes

public static ByteString getBytes(ByteBuffer buffer)
Get a byte string from all remaining bytes of a ByteBuffer.

Parameters:
buffer - the buffer
Returns:
the byte string

getBytes

public static ByteString getBytes(ByteBuffer buffer,
                                  int length)
Get a byte string from a ByteBuffer.

Parameters:
buffer - the buffer
length - the number of bytes to get
Returns:
the byte string

getBytes

public byte[] getBytes()
Get a copy of the bytes of this ByteString.

Returns:
the copy

getBytes

public void getBytes(byte[] dest)
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
dest - the destination array

getBytes

public void getBytes(byte[] dest,
                     int offs)
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
dest - the destination array
offs - the offset into the destination array

getBytes

public void getBytes(byte[] dest,
                     int offs,
                     int len)
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
dest - the destination array
offs - the offset into the destination array
len - the maximum number of bytes to copy

toString

public String toString(String charset)
                throws UnsupportedEncodingException
Convert this byte string to a standard string.

Parameters:
charset - the character set to use
Returns:
the standard string
Throws:
UnsupportedEncodingException - if the charset is unknown

length

public int length()
Get the number of bytes in this byte string.

Returns:
the number of bytes

substring

public ByteString substring(int offs)
Get the substring of this string starting at the given offset.

Parameters:
offs - the offset
Returns:
the substring

substring

public ByteString substring(int offs,
                            int len)
Get the substring of this string starting at the given offset.

Parameters:
offs - the offset
len - the substring length
Returns:
the substring

compareTo

public int compareTo(ByteString o)
Compare this ByteString to another.

Specified by:
compareTo in interface Comparable<ByteString>
Parameters:
o - the other ByteString
Returns:
the comparison result

hashCode

public int hashCode()
Get the hash code for this ByteString.

Overrides:
hashCode in class Object
Returns:
the hash code

equals

public boolean equals(Object obj)
Determine if this ByteString equals another ByteString.

Overrides:
equals in class Object
Parameters:
obj - the other object
Returns:
true if they are equal

equals

public boolean equals(ByteString other)
Determine if this ByteString equals another ByteString.

Parameters:
other - the other object
Returns:
true if they are equal

XNIO API 3.0.4.GA

Copyright © 2010 JBoss, a division of Red Hat, Inc.