Biiig standardization of whitespace. 2 space indents now, no tabs.
[zxing.git] / core / src / com / google / zxing / oned / MultiFormatUPCEANReader.java
1 /*
2  * Copyright 2008 Google Inc.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.oned;
18
19 import com.google.zxing.ReaderException;
20 import com.google.zxing.Result;
21 import com.google.zxing.common.BitArray;
22
23 /**
24  * <p>A reader that can read all available UPC/EAN formats. If a caller wants to try to
25  * read all such formats, it is most efficent to use this implementation rather than invoke
26  * individual readers.</p>
27  *
28  * @author srowen@google.com (Sean Owen)
29  */
30 public final class MultiFormatUPCEANReader extends AbstractOneDReader {
31
32   /**
33    * Reader implementations to which this implementation delegates, in the order
34    * they will be attempted. Order is important.
35    */
36   private final UPCEANReader[] readers = new UPCEANReader[]{
37       new EAN13Reader(), new UPCAReader(), new EAN8Reader(), new UPCEReader()
38   };
39
40   public Result decodeRow(int rowNumber, BitArray row) throws ReaderException {
41     // Compute this location once and reuse it on multiple implementations
42     int[] startGuardPattern = AbstractUPCEANReader.findStartGuardPattern(row);
43     ReaderException saved = null;
44     for (int i = 0; i < readers.length; i++) {
45       try {
46         return readers[i].decodeRow(rowNumber, row, startGuardPattern);
47       } catch (ReaderException re) {
48         saved = re;
49       }
50     }
51     throw saved;
52   }
53
54 }