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;
34 public Result(String text,
36 ResultPoint[] resultPoints,
37 BarcodeFormat format) {
38 if (text == null && rawBytes == null) {
39 throw new IllegalArgumentException("Text and bytes are null");
42 this.rawBytes = rawBytes;
43 this.resultPoints = resultPoints;
45 this.resultMetadata = null;
49 * @return raw text encoded by the barcode, if applicable, otherwise <code>null</code>
51 public String getText() {
56 * @return raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>
58 public byte[] getRawBytes() {
63 * @return points related to the barcode in the image. These are typically points
64 * identifying finder patterns or the corners of the barcode. The exact meaning is
65 * specific to the type of barcode that was decoded.
67 public ResultPoint[] getResultPoints() {
72 * @return {@link BarcodeFormat} representing the format of the barcode that was recognized and decoded
74 public BarcodeFormat getBarcodeFormat() {
79 * @return {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be <code>null</code>.
80 * This contains optional metadata about what was detected about the barcode, like orientation.
82 public Hashtable getResultMetadata() {
83 return resultMetadata;
86 public void putMetadata(ResultMetadataType type, Object value) {
87 if (resultMetadata == null) {
88 resultMetadata = new Hashtable(3);
90 resultMetadata.put(type, value);
93 public String toString() {
95 return "[" + rawBytes.length + " bytes]";