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 com.google.zxing.Result;
22 * Recognizes an NDEF message that encodes a URI according to the
23 * "URI Record Type Definition" specification.
25 * @author srowen@google.com (Sean Owen)
27 public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
29 private static final byte URI_WELL_KNOWN_TYPE = (byte) 0x55;
31 private static final String[] URI_PREFIXES = new String[] {
39 "ftp://anonymous:anonymous@",
70 private final String uri;
72 private NDEFURIParsedResult(String uri) {
73 super(ParsedReaderResultType.NDEF_TEXT);
77 public static NDEFURIParsedResult parse(Result result) {
78 byte[] bytes = result.getRawBytes();
79 if (!isMaybeNDEF(bytes)) {
83 int payloadLength = bytes[2] & 0xFF;
85 // Next 1 byte is type
86 if (bytes[3] != URI_WELL_KNOWN_TYPE) {
90 int identifierCode = bytes[4] & 0xFF;
92 if (identifierCode < URI_PREFIXES.length) {
93 prefix = URI_PREFIXES[identifierCode];
96 String restOfURI = bytesToString(bytes, 5, payloadLength - 1, "UTF-8");
97 String fullURI = prefix == null ? restOfURI : prefix + restOfURI;
98 return new NDEFURIParsedResult(fullURI);
101 public String getURI() {
105 public String getDisplayResult() {