zoukankan      html  css  js  c++  java
  • NDEF文本格式解析

    ============》》Record Type Definition Technical Specificaltions

     

     1 public class TextRecord {
     2     private final String mText;
     3 
     4     private TextRecord(String text) {
     5         // TODO Auto-generated constructor stub
     6 
     7         mText = text;
     8     }
     9 
    10     public String getText() {
    11         return mText;
    12     }
    13 
    14     public static TextRecord parse(NdefRecord ndefRecord) {
    15         //
    16         if (ndefRecord.getTnf() != NdefRecord.TNF_WELL_KNOWN) {
    17             return null;
    18         }
    19 
    20         if (!Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
    21             return null;
    22         }
    23 
    24         try {
    25 
    26             byte[] palyload = ndefRecord.getPayload();
    27             // 根据最高位判断字符编码
    28             String textEncoding = ((palyload[0] & 0x80) == 0) ? "UTF-8"
    29                     : "UTF-16";
    30             // 根据第六位获得语言编码长度
    31             int languageCodeLength = palyload[0] & 0x3f;
    32             // 获得语言编码
    33             String languageCod = new String(palyload, 1, languageCodeLength,
    34                     "US-ASCII");
    35 
    36             String text = new String(palyload, languageCodeLength + 1,
    37                     palyload.length - languageCodeLength - 1, textEncoding);
    38 
    39             return new TextRecord(text);
    40 
    41         } catch (Exception e) {
    42             // TODO: handle exception
    43             throw new IllegalArgumentException();
    44         }
    45 
    46     }
    47 }
  • 相关阅读:
    剑指offer二十九---最小的k个数
    Select2插件 点击、选中事件 解读
    Datatable插件的简单的使用方式 和 学习方式
    java map获取值方式
    mysql delete语句使用别名报错
    springmvc 添加@ResponseBody
    maven 创建后报错
    nodejs
    gulp
    Nodejs-express 4.0框架 简单介绍
  • 原文地址:https://www.cnblogs.com/my334420/p/6910556.html
Copyright © 2011-2022 走看看