2015/07/26 - Apache DirectMemory has been retired.

For more information, please explore the Attic.

public final class

UnicodeUtil

extends Object
java.lang.Object
   ↳ org.apache.directmemory.memory.buffer.UnicodeUtil

Class Overview

Class to encode java's UTF16 char[] into UTF8 byte[] without always allocating a new byte[] as String.getBytes("UTF-8") does.

Summary

Constants
int UNI_REPLACEMENT_CHAR
int UNI_SUR_HIGH_END
int UNI_SUR_HIGH_START
int UNI_SUR_LOW_END
int UNI_SUR_LOW_START
Public Methods
static int UTF16toUTF8(String value, WritableMemoryBuffer target)
Encode characters from the given String, starting at offset 0 for length chars.
static String UTF8toUTF16(ReadableMemoryBuffer source)
Interprets the bytes from the given Source as UTF-8 and converts to UTF-16.
static boolean validUTF16String(char[] s, int size)
static boolean validUTF16String(CharSequence s)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int UNI_REPLACEMENT_CHAR

Constant Value: 65533 (0x0000fffd)

public static final int UNI_SUR_HIGH_END

Constant Value: 56319 (0x0000dbff)

public static final int UNI_SUR_HIGH_START

Constant Value: 55296 (0x0000d800)

public static final int UNI_SUR_LOW_END

Constant Value: 57343 (0x0000dfff)

public static final int UNI_SUR_LOW_START

Constant Value: 56320 (0x0000dc00)

Public Methods

public static int UTF16toUTF8 (String value, WritableMemoryBuffer target)

Encode characters from the given String, starting at offset 0 for length chars. Returns length of the encoded String in bytes.

public static String UTF8toUTF16 (ReadableMemoryBuffer source)

Interprets the bytes from the given Source as UTF-8 and converts to UTF-16.

NOTE: Full characters are read, even if this reads past the length passed (and can result in an ArrayOutOfBoundsException if invalid UTF-8 is passed). Explicit checks for valid UTF-8 are not performed.

public static boolean validUTF16String (char[] s, int size)

public static boolean validUTF16String (CharSequence s)