Interface: Bytes Stay organized with collections Save and categorize content based on your preferences.
rules. Bytes
Type representing a sequence of bytes.
Byte literals are specified using ab declaration prefix followed by bytes represented as a sequence of characters, two-place hexadecimal values (for example,b'\x0F', notb'\xF'), or three-place octal values (for example,b'\000', notb'\0'). Character sequences are interpreted as UTF-8 encoded strings.
// These are all equal to decimal 42.b'*'b'\x2A'b'\052'// These are all equivalentb'€' // 3-byte UTF-8 encoded stringb'\342\202\254'b'\xE2\x82\xAC'
Functions for the Bytes type are provided to aid comparison of byte sequences represented as Base64url- and hexadecimal-encoded strings.
Methods
size
size() returns rules.Integer
Returns the number of bytes in a Bytes sequence.
- Returns
non-nullrules.Integerthe number of bytes.
Example
b'\xFF\xFF'.size() == 2b'a'.size() == 1b'€'.size() == 3 // 3-byte UTF-8 encoded stringtoBase64
toBase64() returns rules.String
Returns the Base64-encoded string corresponding to the provided Bytes sequence.
Base64 encoding is performed per thebase64url specification.
- Returns
non-nullrules.Stringa Base64-encoded string.
Example
b'\xFB\xEF\xBE'.toBase64() == '----'toHexString
toHexString() returns rules.String
Returns the hexadecimal-encoded string corresponding to the provided Bytes sequence.
- Returns
non-nullrules.Stringa hexadecimal-encoded string.
Example
b'\x2A'.toHexString() == '2A'b'**'.toHexString() == '2A2A'b'€'.toHexString() == 'E282AC'Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2019-12-03 UTC.