Package com.helger.base.string
Class StringEncoding
java.lang.Object
com.helger.base.string.StringEncoding
Helper class for encoding char arrays to byte arrays and decoding byte arrays
to char arrays using NIO charset codecs, avoiding intermediate String
objects.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic char @NonNull []decodeBytesToChars(byte @NonNull [] aByteArray, int nOfs, int nLen, @NonNull Charset aCharset) Decode a byte array to a char array using the provided charset.static char @NonNull []decodeBytesToChars(byte @NonNull [] aByteArray, @NonNull Charset aCharset) Decode a byte array to a char array using the provided charset.static byte @NonNull []encodeCharToBytes(char @NonNull [] aCharArray, int nOfs, int nLen, @NonNull Charset aCharset) Encode a char array to a byte array using the provided charset.static byte @NonNull []encodeCharToBytes(char @NonNull [] aCharArray, @NonNull Charset aCharset) Encode a char array to a byte array using the provided charset.
-
Method Details
-
encodeCharToBytes
@ReturnsMutableCopy public static byte @NonNull [] encodeCharToBytes(char @NonNull [] aCharArray, @NonNull Charset aCharset) Encode a char array to a byte array using the provided charset. This does the same asnew String (aCharArray).getBytes (aCharset)just without the intermediate objects.- Parameters:
aCharArray- The char array to be encoded. May not benull.aCharset- Charset to be used. May not benull.- Returns:
- The created byte array. Never
null. - Since:
- 8.6.4
-
encodeCharToBytes
@ReturnsMutableCopy public static byte @NonNull [] encodeCharToBytes(char @NonNull [] aCharArray, @Nonnegative int nOfs, @Nonnegative int nLen, @NonNull Charset aCharset) Encode a char array to a byte array using the provided charset. This does the same asnew String (aCharArray).getBytes (aCharset)just without the intermediate objects.- Parameters:
aCharArray- The char array to be encoded. May not benull.nOfs- Offset into char array. Must be ≥ 0.nLen- Chars to encode. Must be ≥ 0.aCharset- Charset to be used. May not benull.- Returns:
- The created byte array. Never
null. - Since:
- 8.6.4
-
decodeBytesToChars
public static char @NonNull [] decodeBytesToChars(byte @NonNull [] aByteArray, @NonNull Charset aCharset) Decode a byte array to a char array using the provided charset. This does the same asnew String (aByteArray, aCharset)just without the intermediate objects.- Parameters:
aByteArray- The byte array to be decoded. May not benull.aCharset- Charset to be used. May not benull.- Returns:
- The created char array. Never
null. - Since:
- 8.6.4
-
decodeBytesToChars
public static char @NonNull [] decodeBytesToChars(byte @NonNull [] aByteArray, @Nonnegative int nOfs, @Nonnegative int nLen, @NonNull Charset aCharset) Decode a byte array to a char array using the provided charset. This does the same asnew String (aByteArray, aCharset)just without the intermediate objects.- Parameters:
aByteArray- The byte array to be decoded. May not benull.nOfs- Offset into byte array. Must be ≥ 0.nLen- Bytes to encode. Must be ≥ 0.aCharset- Charset to be used. May not benull.- Returns:
- The created char array. Never
null. - Since:
- 8.6.4
-