public final class Converter extends Object
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
toBytes(char[] chars)
Convert a char array to a byte array using the platform's default encoding as returned by
Charset.defaultCharset(). |
static byte[] |
toBytes(char[] chars,
String encoding)
Convert a char array to a byte array using the provided String encoding.
|
static char[] |
toChars(byte[] bytes)
Convert a byte array to a char array using the platform's default encoding as returned by
Charset.defaultCharset(). |
static char[] |
toChars(byte[] bytes,
String encoding)
Convert a byte array to a char array using the provided String encoding.
|
public static byte[] toBytes(char[] chars)
Charset.defaultCharset().
When writing portable code, it is commonly a better practice to use toBytes(char[], String)
instead of this method, and specify the encoding explicitly to avoid porting problems.
Note that this method does not change the provided source array.
chars - The char array to convertpublic static byte[] toBytes(char[] chars,
String encoding)
Note that this method does not change the provided source array.
chars - The char array to convertencoding - The string encoding to useNullPointerException - When encoding is nullIllegalArgumentException - When encoding is emptyUnsupportedCharsetException - When encoding is invalidpublic static char[] toChars(byte[] bytes)
Charset.defaultCharset().
When writing portable code, it is commonly a better practice to use toBytes(char[], String)
instead of this method, and specify the encoding explicitly to avoid porting problems.
Note that this method does not change the provided source array.
bytes - The byte array to convertpublic static char[] toChars(byte[] bytes,
String encoding)
Note that this method does not change the provided source array.
bytes - The byte array to convertencoding - The string encoding to useNullPointerException - When encoding is nullIllegalArgumentException - When encoding is emptyUnsupportedCharsetException - When encoding is invalidCopyright © 2014–2016 Michael Beiter