mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Don't throw IllegalArgumentException in RSS reader; use checked FormatException to fit into BS error checking mechanism correctly
git-svn-id: https://zxing.googlecode.com/svn/trunk@2893 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
6c103e7840
commit
f84c8470a4
|
@ -28,6 +28,7 @@ package com.google.zxing.oned.rss.expanded;
|
|||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultPoint;
|
||||
|
@ -122,7 +123,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
@Override
|
||||
public Result decodeRow(int rowNumber,
|
||||
BitArray row,
|
||||
Map<DecodeHintType,?> hints) throws NotFoundException {
|
||||
Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
|
||||
// Rows can start with even pattern in case in prev rows there where odd number of patters.
|
||||
// So lets try twice
|
||||
this.pairs.clear();
|
||||
|
@ -362,7 +363,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
}
|
||||
|
||||
// Not private for unit testing
|
||||
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException{
|
||||
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException {
|
||||
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
|
||||
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -42,7 +43,7 @@ final class AI01392xDecoder extends AI01decoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -42,7 +43,7 @@ final class AI01393xDecoder extends AI01decoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
if(this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -42,7 +43,7 @@ final class AI01AndOtherAIs extends AI01decoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
StringBuilder buff = new StringBuilder();
|
||||
|
||||
buff.append("(01)");
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -51,7 +52,7 @@ public abstract class AbstractExpandedDecoder {
|
|||
return generalDecoder;
|
||||
}
|
||||
|
||||
public abstract String parseInformation() throws NotFoundException;
|
||||
public abstract String parseInformation() throws NotFoundException, FormatException;
|
||||
|
||||
public static AbstractExpandedDecoder createDecoder(BitArray information){
|
||||
if (information.get(1)) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -42,7 +43,7 @@ final class AnyAIDecoder extends AbstractExpandedDecoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInformation() throws NotFoundException {
|
||||
public String parseInformation() throws NotFoundException, FormatException {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
return this.getGeneralDecoder().decodeAllCodes(buf, HEADER_SIZE);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
|
||||
|
@ -37,19 +39,15 @@ final class DecodedNumeric extends DecodedObject {
|
|||
|
||||
static final int FNC1 = 10;
|
||||
|
||||
DecodedNumeric(int newPosition, int firstDigit, int secondDigit){
|
||||
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
|
||||
super(newPosition);
|
||||
|
||||
if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
||||
this.firstDigit = firstDigit;
|
||||
this.secondDigit = secondDigit;
|
||||
|
||||
if (this.firstDigit < 0 || this.firstDigit > 10) {
|
||||
throw new IllegalArgumentException("Invalid firstDigit: " + firstDigit);
|
||||
}
|
||||
|
||||
if (this.secondDigit < 0 || this.secondDigit > 10) {
|
||||
throw new IllegalArgumentException("Invalid secondDigit: " + secondDigit);
|
||||
}
|
||||
}
|
||||
|
||||
int getFirstDigit(){
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
|
@ -43,7 +44,7 @@ final class GeneralAppIdDecoder {
|
|||
this.information = information;
|
||||
}
|
||||
|
||||
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException {
|
||||
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException, FormatException {
|
||||
int currentPosition = initialPosition;
|
||||
String remaining = null;
|
||||
do{
|
||||
|
@ -83,7 +84,7 @@ final class GeneralAppIdDecoder {
|
|||
return this.information.get(pos + 3);
|
||||
}
|
||||
|
||||
private DecodedNumeric decodeNumeric(int pos) {
|
||||
private DecodedNumeric decodeNumeric(int pos) throws FormatException {
|
||||
if(pos + 7 > this.information.getSize()){
|
||||
int numeric = extractNumericValueFromBitArray(pos, 4);
|
||||
if(numeric == 0) {
|
||||
|
@ -104,10 +105,6 @@ final class GeneralAppIdDecoder {
|
|||
}
|
||||
|
||||
static int extractNumericValueFromBitArray(BitArray information, int pos, int bits) {
|
||||
if(bits > 32) {
|
||||
throw new IllegalArgumentException("extractNumberValueFromBitArray can't handle more than 32 bits");
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
for (int i = 0; i < bits; ++i) {
|
||||
if (information.get(pos + i)) {
|
||||
|
@ -118,7 +115,7 @@ final class GeneralAppIdDecoder {
|
|||
return value;
|
||||
}
|
||||
|
||||
DecodedInformation decodeGeneralPurposeField(int pos, String remaining) {
|
||||
DecodedInformation decodeGeneralPurposeField(int pos, String remaining) throws FormatException {
|
||||
this.buffer.setLength(0);
|
||||
|
||||
if(remaining != null) {
|
||||
|
@ -134,7 +131,7 @@ final class GeneralAppIdDecoder {
|
|||
return new DecodedInformation(this.current.getPosition(), this.buffer.toString());
|
||||
}
|
||||
|
||||
private DecodedInformation parseBlocks() {
|
||||
private DecodedInformation parseBlocks() throws FormatException {
|
||||
boolean isFinished;
|
||||
BlockParsedResult result;
|
||||
do{
|
||||
|
@ -160,7 +157,7 @@ final class GeneralAppIdDecoder {
|
|||
return result.getDecodedInformation();
|
||||
}
|
||||
|
||||
private BlockParsedResult parseNumericBlock() {
|
||||
private BlockParsedResult parseNumericBlock() throws FormatException {
|
||||
while (isStillNumeric(current.getPosition())) {
|
||||
DecodedNumeric numeric = decodeNumeric(current.getPosition());
|
||||
current.setPosition(numeric.getNewPosition());
|
||||
|
@ -190,7 +187,7 @@ final class GeneralAppIdDecoder {
|
|||
return new BlockParsedResult(false);
|
||||
}
|
||||
|
||||
private BlockParsedResult parseIsoIec646Block() {
|
||||
private BlockParsedResult parseIsoIec646Block() throws FormatException {
|
||||
while (isStillIsoIec646(current.getPosition())) {
|
||||
DecodedChar iso = decodeIsoIec646(current.getPosition());
|
||||
current.setPosition(iso.getNewPosition());
|
||||
|
@ -273,7 +270,7 @@ final class GeneralAppIdDecoder {
|
|||
|
||||
}
|
||||
|
||||
private DecodedChar decodeIsoIec646(int pos) {
|
||||
private DecodedChar decodeIsoIec646(int pos) throws FormatException {
|
||||
int fiveBitValue = extractNumericValueFromBitArray(pos, 5);
|
||||
if (fiveBitValue == 15) {
|
||||
return new DecodedChar(pos + 5, DecodedChar.FNC1);
|
||||
|
@ -360,7 +357,7 @@ final class GeneralAppIdDecoder {
|
|||
c = ' ';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Decoding invalid ISO/IEC 646 value: " + eightBitValue);
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
return new DecodedChar(pos + 8, c);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package com.google.zxing.oned.rss.expanded.decoders;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.oned.rss.expanded.BinaryUtil;
|
||||
|
@ -67,7 +68,7 @@ public abstract class AbstractDecoderTest extends Assert {
|
|||
protected static final String compressedDate_End = "X..X.XX.........";
|
||||
|
||||
protected static void assertCorrectBinaryString(CharSequence binaryString,
|
||||
String expectedNumber) throws NotFoundException {
|
||||
String expectedNumber) throws NotFoundException, FormatException {
|
||||
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
|
||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
||||
String result = decoder.parseInformation();
|
||||
|
|
Loading…
Reference in a new issue