2 * Copyright 2008 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import java.io.UnsupportedEncodingException;
22 * <p>Superclass for classes encapsulating results in the NDEF format.
23 * See <a href="http://www.nfc-forum.org/specs/">http://www.nfc-forum.org/specs/</a>.</p>
25 * <p>This code supports a limited subset of NDEF messages, ones that are plausibly
26 * useful in 2D barcode formats. This generally includes 1-record messages, no chunking,
27 * "short record" syntax, no ID field.</p>
29 * @author srowen@google.com (Sean Owen)
31 abstract class AbstractNDEFParsedResult extends ParsedReaderResult {
34 * MB = 1 (start of record)
35 * ME = 1 (also end of record)
36 * CF = 0 (not a chunk)
37 * SR = 1 (assume short record)
38 * ID = 0 (ID length field omitted)
39 * TNF = 0 (= 1, well-known type)
43 private static final int HEADER_VALUE = 0xD1;
44 private static final int MASK = 0xFF;
46 AbstractNDEFParsedResult(ParsedReaderResultType type) {
50 static boolean isMaybeNDEF(byte[] bytes) {
54 ((bytes[0] & MASK) == HEADER_VALUE) &&
55 ((bytes[1] & 0xFF) == 1);
58 static String bytesToString(byte[] bytes, int offset, int length, String encoding) {
60 return new String(bytes, offset, length, encoding);
61 } catch (UnsupportedEncodingException uee) {
62 throw new RuntimeException("Platform does not support required encoding: " + uee);