2 * Copyright 2008 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.oned;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.DecodeHintType;
21 import com.google.zxing.ReaderException;
22 import com.google.zxing.Result;
23 import com.google.zxing.common.BitArray;
25 import java.util.Hashtable;
26 import java.util.Vector;
29 * @author dswitkin@google.com (Daniel Switkin)
32 public final class MultiFormatOneDReader extends OneDReader {
34 private final Vector readers;
36 public MultiFormatOneDReader(Hashtable hints) {
37 Vector possibleFormats = hints == null ? null :
38 (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
39 boolean useCode39CheckDigit = hints != null &&
40 hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
41 readers = new Vector();
42 if (possibleFormats != null) {
43 if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
44 possibleFormats.contains(BarcodeFormat.UPC_A) ||
45 possibleFormats.contains(BarcodeFormat.EAN_8) ||
46 possibleFormats.contains(BarcodeFormat.UPC_E)) {
47 readers.addElement(new MultiFormatUPCEANReader(hints));
49 if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
50 readers.addElement(new Code39Reader(useCode39CheckDigit));
52 if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
53 readers.addElement(new Code128Reader());
55 if (possibleFormats.contains(BarcodeFormat.ITF)) {
56 readers.addElement(new ITFReader());
59 if (readers.isEmpty()) {
60 readers.addElement(new MultiFormatUPCEANReader(hints));
61 readers.addElement(new Code39Reader());
62 readers.addElement(new Code128Reader());
63 readers.addElement(new ITFReader());
67 public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
68 int size = readers.size();
69 for (int i = 0; i < size; i++) {
70 OneDReader reader = (OneDReader) readers.elementAt(i);
72 return reader.decodeRow(rowNumber, row, hints);
73 } catch (ReaderException re) {
78 throw ReaderException.getInstance();