Code example for Locale

Methods: getLanguage

0
        return newTextRecord(text, locale, true);
    } 
 
    public static NdefRecord newTextRecord(String text, Locale locale, boolean encodeInUtf8) {
        Preconditions.checkNotNull(text);
        Preconditions.checkNotNull(locale);
 
        byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII"));
 
        Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16");
        byte[] textBytes = text.getBytes(utfEncoding);
 
        int utfBit = encodeInUtf8 ? 0 : (1 << 7);
        char status = (char) (utfBit + langBytes.length);
 
        byte[] data = Bytes.concat(
           new byte[] { (byte) status },
           langBytes,
           textBytes
        );