I need to send String to client socket, for right sequence, the endian is important but I not saw endian information in source code.Does it needn't care about or just I skipped those code?
getBytes() This function takes no arguments and used the default charset to encode the string into bytes. getbytes() function in java is used to convert a string into a sequence of bytes and returns an array of bytes. Syntax: public byte[] getBytes()
There are three variants of getBytes() method. The signature or syntax of string getBytes() method is given below: public byte[] getBytes() public byte[] getBytes(Charset charset)
Specifically, little-endian is when the least significant bytes are stored before the more significant bytes, and big-endian is when the most significant bytes are stored before the less significant bytes. When we write a number (in hex), i.e. 0x12345678 , we write it with the most significant byte first (the 12 part).
In the Big-Endian storage order, the "big", most significant, byte 0x44 is stored "first", at the lowest memory location 101. The 0x44 displays to the left of the other bytes, which follow in ascending left-to-right memory address order: 102, 103, 104.
getBytes()
uses the system's default charset, which means basically all bets are off. It could be big-endian UTF-16, little-endian UTF-16, UTF-8, ISO-8859-1... basically anything.
If you need to specify endianness, or anything about the charset for that matter, you should use getBytes(Charset)
or getBytes(String)
. There are a few standard charsets that all JREs support — including UTF_16BE (big endian) and UTF_16LE (little endian).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With