Every Java platform has a default character encoding. The available encodings are listed in the Supported Encodings document [Encodings 2014]. A conversion between characters and sequences of bytes requires a character encoding to specify the details of the conversion. Such conversions use the system default encoding in the absence of an explicitly specified encoding. When characters are converted into an array of bytes to be sent as output, transmitted across some communication channel, input, and converted back into characters, compatible encodings must be used on both sides of the conversation. Disagreement over character encodings can cause data corruption.
According to the Java API [API 2014] for the String
class:
The length of the new
String
is a function of the charset, and for that reason may not be equal to the length of the byte array. The behavior of this constructor when the given bytes are not valid in the given charset is unspecified.
Binary data that is expected to be a valid string may be read and converted to a string by exception STR04-EX0Disagreement over character encodings can result in data corruption.
Noncompliant Code Example
...