2 * Copyright 2007 ZXing authors
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;
19 import java.util.Hashtable;
22 * <p>Encapsulates the result of decoding a barcode within an image.</p>
26 public final class Result {
28 private final String text;
29 private final byte[] rawBytes;
30 private final ResultPoint[] resultPoints;
31 private final BarcodeFormat format;
32 private Hashtable resultMetadata;
33 private final long timestamp;
35 public Result(String text,
37 ResultPoint[] resultPoints,
38 BarcodeFormat format) {
39 this(text, rawBytes, resultPoints, format, System.currentTimeMillis());
42 public Result(String text,
44 ResultPoint[] resultPoints,
47 if (text == null && rawBytes == null) {
48 throw new IllegalArgumentException("Text and bytes are null");
51 this.rawBytes = rawBytes;
52 this.resultPoints = resultPoints;
54 this.resultMetadata = null;
55 this.timestamp = timestamp;
59 * @return raw text encoded by the barcode, if applicable, otherwise <code>null</code>
61 public String getText() {
66 * @return raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>
68 public byte[] getRawBytes() {
73 * @return points related to the barcode in the image. These are typically points
74 * identifying finder patterns or the corners of the barcode. The exact meaning is
75 * specific to the type of barcode that was decoded.
77 public ResultPoint[] getResultPoints() {
82 * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
84 public BarcodeFormat getBarcodeFormat() {
89 * @return {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be
90 * <code>null</code>. This contains optional metadata about what was detected about the barcode,
93 public Hashtable getResultMetadata() {
94 return resultMetadata;
97 public void putMetadata(ResultMetadataType type, Object value) {
98 if (resultMetadata == null) {
99 resultMetadata = new Hashtable(3);
101 resultMetadata.put(type, value);
104 public long getTimestamp() {
108 public String toString() {
110 return "[" + rawBytes.length + " bytes]";