Package org.robolectric.res.android
Class ResourceString
- java.lang.Object
-
- org.robolectric.res.android.ResourceString
-
public final class ResourceString extends Object
Provides utilities to decode/encode a String packed in an arsc resource file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceString.TypeType ofResourceStringto encode / decode.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbuildString(char[] data)Builds a string from a null-terminated char data.static StringdecodeString(ByteBuffer buffer, int offset, ResourceString.Type type)Given a buffer and an offset into the buffer, returns a String.static byte[]encodeString(String str, ResourceString.Type type)Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
-
-
-
Method Detail
-
decodeString
public static String decodeString(ByteBuffer buffer, int offset, ResourceString.Type type)
Given a buffer and an offset into the buffer, returns a String. Theoffsetis the 0-based byte offset from the start of the buffer where the string resides. This should be the location in memory where the string's character count, followed by its byte count, and then followed by the actual string is located.Here's an example UTF-8-encoded string of ab©:
03 04 61 62 C2 A9 00 ^ Offset should be here
- Parameters:
buffer- The buffer containing the string to decode.offset- Offset into the buffer where the string resides.type- The encoding type that theResourceStringis encoded in.- Returns:
- The decoded string.
-
encodeString
public static byte[] encodeString(String str, ResourceString.Type type)
Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string. Strings are prefixed by 2 values. The first is the number of characters in the string. The second is the encoding length (number of bytes in the string).Here's an example UTF-8-encoded string of ab©:
03 04 61 62 C2 A9 00
- Parameters:
str- The string to be encoded.type- The encoding type that theResourceStringshould be encoded in.- Returns:
- The encoded string.
-
buildString
public static String buildString(char[] data)
Builds a string from a null-terminated char data.
-
-