mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Many more changes from recent IJ inspections
This commit is contained in:
parent
431ae9e06e
commit
36f38c5beb
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
||||||
target
|
target
|
||||||
private
|
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
@ -40,6 +40,7 @@ import android.util.Log;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -195,7 +196,7 @@ final class QRCodeEncoder {
|
||||||
baos.write(buffer, 0, bytesRead);
|
baos.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
vcard = baos.toByteArray();
|
vcard = baos.toByteArray();
|
||||||
vcardString = new String(vcard, 0, vcard.length, "UTF-8");
|
vcardString = new String(vcard, 0, vcard.length, StandardCharsets.UTF_8);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new WriterException(ioe);
|
throw new WriterException(ioe);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ final class BookResultInfoRetriever extends SupplementalInfoRetriever {
|
||||||
String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
|
String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
|
||||||
+ "/search?tbm=bks&source=zxing&q=";
|
+ "/search?tbm=bks&source=zxing&q=";
|
||||||
|
|
||||||
append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
|
append(isbn, source, newTexts.toArray(EMPTY_STR_ARRAY), baseBookUri + isbn);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
|
||||||
|
|
||||||
private static final String TAG = "SupplementalInfo";
|
private static final String TAG = "SupplementalInfo";
|
||||||
|
|
||||||
|
static final String[] EMPTY_STR_ARRAY = new String[0];
|
||||||
|
|
||||||
private final WeakReference<TextView> textViewRef;
|
private final WeakReference<TextView> textViewRef;
|
||||||
private final WeakReference<HistoryManager> historyManagerRef;
|
private final WeakReference<HistoryManager> historyManagerRef;
|
||||||
private final Collection<Spannable> newContents;
|
private final Collection<Spannable> newContents;
|
||||||
|
|
|
@ -37,6 +37,8 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public final class MultiFormatReader implements Reader {
|
public final class MultiFormatReader implements Reader {
|
||||||
|
|
||||||
|
private static final Reader[] EMPTY_READER_ARRAY = new Reader[0];
|
||||||
|
|
||||||
private Map<DecodeHintType,?> hints;
|
private Map<DecodeHintType,?> hints;
|
||||||
private Reader[] readers;
|
private Reader[] readers;
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ public final class MultiFormatReader implements Reader {
|
||||||
readers.add(new MultiFormatOneDReader(hints));
|
readers.add(new MultiFormatOneDReader(hints));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.readers = readers.toArray(new Reader[readers.size()]);
|
this.readers = readers.toArray(EMPTY_READER_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This produces nearly optimal encodings of text into the first-level of
|
* This produces nearly optimal encodings of text into the first-level of
|
||||||
|
@ -284,7 +283,7 @@ public final class HighLevelEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<State> simplifyStates(Iterable<State> states) {
|
private static Collection<State> simplifyStates(Iterable<State> states) {
|
||||||
List<State> result = new LinkedList<>();
|
Collection<State> result = new LinkedList<>();
|
||||||
for (State newState : states) {
|
for (State newState : states) {
|
||||||
boolean add = true;
|
boolean add = true;
|
||||||
for (Iterator<State> iterator = result.iterator(); iterator.hasNext();) {
|
for (Iterator<State> iterator = result.iterator(); iterator.hasNext();) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public final class AddressBookAUResultParser extends ResultParser {
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return values.toArray(new String[values.size()]);
|
return values.toArray(EMPTY_STR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ public abstract class ResultParser {
|
||||||
private static final Pattern EQUALS = Pattern.compile("=");
|
private static final Pattern EQUALS = Pattern.compile("=");
|
||||||
private static final String BYTE_ORDER_MARK = "\ufeff";
|
private static final String BYTE_ORDER_MARK = "\ufeff";
|
||||||
|
|
||||||
|
static final String[] EMPTY_STR_ARRAY = new String[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to parse the raw {@link Result}'s contents as a particular type
|
* Attempts to parse the raw {@link Result}'s contents as a particular type
|
||||||
* of information (email, URL, etc.) and return a {@link ParsedResult} encapsulating
|
* of information (email, URL, etc.) and return a {@link ParsedResult} encapsulating
|
||||||
|
@ -236,7 +238,7 @@ public abstract class ResultParser {
|
||||||
if (matches == null || matches.isEmpty()) {
|
if (matches == null || matches.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return matches.toArray(new String[matches.size()]);
|
return matches.toArray(EMPTY_STR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int countPrecedingBackslashes(CharSequence s, int pos) {
|
private static int countPrecedingBackslashes(CharSequence s, int pos) {
|
||||||
|
|
|
@ -80,8 +80,8 @@ public final class SMSMMSResultParser extends ResultParser {
|
||||||
}
|
}
|
||||||
addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1));
|
addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1));
|
||||||
|
|
||||||
return new SMSParsedResult(numbers.toArray(new String[numbers.size()]),
|
return new SMSParsedResult(numbers.toArray(EMPTY_STR_ARRAY),
|
||||||
vias.toArray(new String[vias.size()]),
|
vias.toArray(EMPTY_STR_ARRAY),
|
||||||
subject,
|
subject,
|
||||||
body);
|
body);
|
||||||
}
|
}
|
||||||
|
@ -106,4 +106,4 @@ public final class SMSMMSResultParser extends ResultParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,7 +296,7 @@ public final class VCardResultParser extends ResultParser {
|
||||||
result.add(value);
|
result.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new String[result.size()]);
|
return result.toArray(EMPTY_STR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] toTypes(Collection<List<String>> lists) {
|
private static String[] toTypes(Collection<List<String>> lists) {
|
||||||
|
@ -324,7 +324,7 @@ public final class VCardResultParser extends ResultParser {
|
||||||
result.add(type);
|
result.add(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new String[result.size()]);
|
return result.toArray(EMPTY_STR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLikeVCardDate(CharSequence value) {
|
private static boolean isLikeVCardDate(CharSequence value) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ public final class BitArray implements Cloneable {
|
||||||
int bitsOffset = from / 32;
|
int bitsOffset = from / 32;
|
||||||
int currentBits = bits[bitsOffset];
|
int currentBits = bits[bitsOffset];
|
||||||
// mask off lesser bits first
|
// mask off lesser bits first
|
||||||
currentBits &= ~((1 << (from & 0x1F)) - 1);
|
currentBits &= -(1 << (from & 0x1F));
|
||||||
while (currentBits == 0) {
|
while (currentBits == 0) {
|
||||||
if (++bitsOffset == bits.length) {
|
if (++bitsOffset == bits.length) {
|
||||||
return size;
|
return size;
|
||||||
|
@ -122,7 +122,7 @@ public final class BitArray implements Cloneable {
|
||||||
int bitsOffset = from / 32;
|
int bitsOffset = from / 32;
|
||||||
int currentBits = ~bits[bitsOffset];
|
int currentBits = ~bits[bitsOffset];
|
||||||
// mask off lesser bits first
|
// mask off lesser bits first
|
||||||
currentBits &= ~((1 << (from & 0x1F)) - 1);
|
currentBits &= -(1 << (from & 0x1F));
|
||||||
while (currentBits == 0) {
|
while (currentBits == 0) {
|
||||||
if (++bitsOffset == bits.length) {
|
if (++bitsOffset == bits.length) {
|
||||||
return size;
|
return size;
|
||||||
|
|
|
@ -90,7 +90,6 @@ public final class WhiteRectangleDetector {
|
||||||
int down = downInit;
|
int down = downInit;
|
||||||
boolean sizeExceeded = false;
|
boolean sizeExceeded = false;
|
||||||
boolean aBlackPointFoundOnBorder = true;
|
boolean aBlackPointFoundOnBorder = true;
|
||||||
boolean atLeastOneBlackPointFoundOnBorder = false;
|
|
||||||
|
|
||||||
boolean atLeastOneBlackPointFoundOnRight = false;
|
boolean atLeastOneBlackPointFoundOnRight = false;
|
||||||
boolean atLeastOneBlackPointFoundOnBottom = false;
|
boolean atLeastOneBlackPointFoundOnBottom = false;
|
||||||
|
@ -181,13 +180,9 @@ public final class WhiteRectangleDetector {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aBlackPointFoundOnBorder) {
|
|
||||||
atLeastOneBlackPointFoundOnBorder = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
|
if (!sizeExceeded) {
|
||||||
|
|
||||||
int maxSize = right - left;
|
int maxSize = right - left;
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,7 @@ class C40Encoder implements Encoder {
|
||||||
if ((buffer.length() % 3) == 2 && (available < 2 || available > 2)) {
|
if ((buffer.length() % 3) == 2 && (available < 2 || available > 2)) {
|
||||||
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
|
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
|
||||||
}
|
}
|
||||||
while ((buffer.length() % 3) == 1
|
while ((buffer.length() % 3) == 1 && (lastCharSize > 3 || available != 1)) {
|
||||||
&& ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
|
|
||||||
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
|
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -59,14 +59,10 @@ public final class MaxiCodeReader implements Reader {
|
||||||
@Override
|
@Override
|
||||||
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||||
throws NotFoundException, ChecksumException, FormatException {
|
throws NotFoundException, ChecksumException, FormatException {
|
||||||
DecoderResult decoderResult;
|
// Note that MaxiCode reader effectively always assumes PURE_BARCODE mode
|
||||||
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
|
// and can't detect it in an image
|
||||||
BitMatrix bits = extractPureBits(image.getBlackMatrix());
|
BitMatrix bits = extractPureBits(image.getBlackMatrix());
|
||||||
decoderResult = decoder.decode(bits, hints);
|
DecoderResult decoderResult = decoder.decode(bits, hints);
|
||||||
} else {
|
|
||||||
throw NotFoundException.getNotFoundInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
|
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
|
||||||
|
|
||||||
String ecLevel = decoderResult.getECLevel();
|
String ecLevel = decoderResult.getECLevel();
|
||||||
|
|
|
@ -47,6 +47,8 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
|
||||||
private static final int MIN_DIMENSION_TO_RECUR = 100;
|
private static final int MIN_DIMENSION_TO_RECUR = 100;
|
||||||
private static final int MAX_DEPTH = 4;
|
private static final int MAX_DEPTH = 4;
|
||||||
|
|
||||||
|
static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
|
||||||
|
|
||||||
private final Reader delegate;
|
private final Reader delegate;
|
||||||
|
|
||||||
public GenericMultipleBarcodeReader(Reader delegate) {
|
public GenericMultipleBarcodeReader(Reader delegate) {
|
||||||
|
@ -66,7 +68,7 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader
|
||||||
if (results.isEmpty()) {
|
if (results.isEmpty()) {
|
||||||
throw NotFoundException.getNotFoundInstance();
|
throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
return results.toArray(new Result[results.size()]);
|
return results.toArray(EMPTY_RESULT_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDecodeMultiple(BinaryBitmap image,
|
private void doDecodeMultiple(BinaryBitmap image,
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
|
||||||
return EMPTY_RESULT_ARRAY;
|
return EMPTY_RESULT_ARRAY;
|
||||||
} else {
|
} else {
|
||||||
results = processStructuredAppend(results);
|
results = processStructuredAppend(results);
|
||||||
return results.toArray(new Result[results.size()]);
|
return results.toArray(EMPTY_RESULT_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public final class MultiDetector extends Detector {
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return EMPTY_DETECTOR_RESULTS;
|
return EMPTY_DETECTOR_RESULTS;
|
||||||
} else {
|
} else {
|
||||||
return result.toArray(new DetectorResult[result.size()]);
|
return result.toArray(EMPTY_DETECTOR_RESULTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ import java.util.Map;
|
||||||
final class MultiFinderPatternFinder extends FinderPatternFinder {
|
final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
|
|
||||||
private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
|
private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
|
||||||
|
private static final FinderPattern[][] EMPTY_FP_2D_ARRAY = new FinderPattern[0][];
|
||||||
|
|
||||||
// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
|
// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
|
||||||
// since it limits the number of regions to decode
|
// since it limits the number of regions to decode
|
||||||
|
@ -216,12 +217,12 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
|
|
||||||
// All tests passed!
|
// All tests passed!
|
||||||
results.add(test);
|
results.add(test);
|
||||||
} // end iterate p3
|
}
|
||||||
} // end iterate p2
|
}
|
||||||
} // end iterate p1
|
}
|
||||||
|
|
||||||
if (!results.isEmpty()) {
|
if (!results.isEmpty()) {
|
||||||
return results.toArray(new FinderPattern[results.size()][]);
|
return results.toArray(EMPTY_FP_2D_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing found!
|
// Nothing found!
|
||||||
|
@ -279,7 +280,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
|
|
||||||
if (foundPatternCross(stateCount)) {
|
if (foundPatternCross(stateCount)) {
|
||||||
handlePossibleCenter(stateCount, i, maxJ);
|
handlePossibleCenter(stateCount, i, maxJ);
|
||||||
} // end if foundPatternCross
|
}
|
||||||
} // for i=iSkip-1 ...
|
} // for i=iSkip-1 ...
|
||||||
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
|
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
|
||||||
List<FinderPatternInfo> result = new ArrayList<>();
|
List<FinderPatternInfo> result = new ArrayList<>();
|
||||||
|
@ -291,7 +292,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return EMPTY_RESULT_ARRAY;
|
return EMPTY_RESULT_ARRAY;
|
||||||
} else {
|
} else {
|
||||||
return result.toArray(new FinderPatternInfo[result.size()]);
|
return result.toArray(EMPTY_RESULT_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public final class MultiFormatOneDReader extends OneDReader {
|
public final class MultiFormatOneDReader extends OneDReader {
|
||||||
|
|
||||||
|
private static final OneDReader[] EMPTY_ONED_ARRAY = new OneDReader[0];
|
||||||
|
|
||||||
private final OneDReader[] readers;
|
private final OneDReader[] readers;
|
||||||
|
|
||||||
public MultiFormatOneDReader(Map<DecodeHintType,?> hints) {
|
public MultiFormatOneDReader(Map<DecodeHintType,?> hints) {
|
||||||
|
@ -84,7 +86,7 @@ public final class MultiFormatOneDReader extends OneDReader {
|
||||||
readers.add(new RSS14Reader());
|
readers.add(new RSS14Reader());
|
||||||
readers.add(new RSSExpandedReader());
|
readers.add(new RSSExpandedReader());
|
||||||
}
|
}
|
||||||
this.readers = readers.toArray(new OneDReader[readers.size()]);
|
this.readers = readers.toArray(EMPTY_ONED_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,6 +37,8 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public final class MultiFormatUPCEANReader extends OneDReader {
|
public final class MultiFormatUPCEANReader extends OneDReader {
|
||||||
|
|
||||||
|
private static final UPCEANReader[] EMPTY_READER_ARRAY = new UPCEANReader[0];
|
||||||
|
|
||||||
private final UPCEANReader[] readers;
|
private final UPCEANReader[] readers;
|
||||||
|
|
||||||
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
|
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
|
||||||
|
@ -63,7 +65,7 @@ public final class MultiFormatUPCEANReader extends OneDReader {
|
||||||
readers.add(new EAN8Reader());
|
readers.add(new EAN8Reader());
|
||||||
readers.add(new UPCEReader());
|
readers.add(new UPCEReader());
|
||||||
}
|
}
|
||||||
this.readers = readers.toArray(new UPCEANReader[readers.size()]);
|
this.readers = readers.toArray(EMPTY_READER_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,6 +43,8 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public final class PDF417Reader implements Reader, MultipleBarcodeReader {
|
public final class PDF417Reader implements Reader, MultipleBarcodeReader {
|
||||||
|
|
||||||
|
private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locates and decodes a PDF417 code in an image.
|
* Locates and decodes a PDF417 code in an image.
|
||||||
*
|
*
|
||||||
|
@ -94,7 +96,7 @@ public final class PDF417Reader implements Reader, MultipleBarcodeReader {
|
||||||
}
|
}
|
||||||
results.add(result);
|
results.add(result);
|
||||||
}
|
}
|
||||||
return results.toArray(new Result[results.size()]);
|
return results.toArray(EMPTY_RESULT_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMaxWidth(ResultPoint p1, ResultPoint p2) {
|
private static int getMaxWidth(ResultPoint p1, ResultPoint p2) {
|
||||||
|
|
|
@ -256,7 +256,7 @@ public final class PDF417ScanningDecoder {
|
||||||
Collection<Integer> erasures = new ArrayList<>();
|
Collection<Integer> erasures = new ArrayList<>();
|
||||||
int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
|
int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
|
||||||
List<int[]> ambiguousIndexValuesList = new ArrayList<>();
|
List<int[]> ambiguousIndexValuesList = new ArrayList<>();
|
||||||
List<Integer> ambiguousIndexesList = new ArrayList<>();
|
Collection<Integer> ambiguousIndexesList = new ArrayList<>();
|
||||||
for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
|
for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
|
||||||
for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
|
for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
|
||||||
int[] values = barcodeMatrix[row][column + 1].getValue();
|
int[] values = barcodeMatrix[row][column + 1].getValue();
|
||||||
|
|
|
@ -19,9 +19,9 @@ package com.google.zxing.multi.qrcode;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.BinaryBitmap;
|
import com.google.zxing.BinaryBitmap;
|
||||||
|
@ -55,14 +55,14 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||||
assertNotNull(results);
|
assertNotNull(results);
|
||||||
assertEquals(4, results.length);
|
assertEquals(4, results.length);
|
||||||
|
|
||||||
Set<String> barcodeContents = new HashSet<>();
|
Collection<String> barcodeContents = new HashSet<>();
|
||||||
for (Result result : results) {
|
for (Result result : results) {
|
||||||
barcodeContents.add(result.getText());
|
barcodeContents.add(result.getText());
|
||||||
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
||||||
Map<ResultMetadataType,Object> metadata = result.getResultMetadata();
|
Map<ResultMetadataType,Object> metadata = result.getResultMetadata();
|
||||||
assertNotNull(metadata);
|
assertNotNull(metadata);
|
||||||
}
|
}
|
||||||
Set<String> expectedContents = new HashSet<>();
|
Collection<String> expectedContents = new HashSet<>();
|
||||||
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
||||||
expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!");
|
expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!");
|
||||||
expectedContents.add("You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)");
|
expectedContents.add("You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)");
|
||||||
|
|
|
@ -105,7 +105,7 @@ public final class CommandLineRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<URI> expand(List<URI> inputs) throws IOException {
|
private static List<URI> expand(Iterable<URI> inputs) throws IOException {
|
||||||
List<URI> expanded = new ArrayList<>();
|
List<URI> expanded = new ArrayList<>();
|
||||||
for (URI input : inputs) {
|
for (URI input : inputs) {
|
||||||
if (isFileOrDir(input)) {
|
if (isFileOrDir(input)) {
|
||||||
|
@ -132,7 +132,7 @@ public final class CommandLineRunner {
|
||||||
return expanded;
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<URI> retainValid(List<URI> inputs, boolean recursive) {
|
private static List<URI> retainValid(Iterable<URI> inputs, boolean recursive) {
|
||||||
List<URI> retained = new ArrayList<>();
|
List<URI> retained = new ArrayList<>();
|
||||||
for (URI input : inputs) {
|
for (URI input : inputs) {
|
||||||
boolean retain;
|
boolean retain;
|
||||||
|
@ -151,7 +151,7 @@ public final class CommandLineRunner {
|
||||||
return retained;
|
return retained;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExpandable(List<URI> inputs) {
|
private static boolean isExpandable(Iterable<URI> inputs) {
|
||||||
for (URI input : inputs) {
|
for (URI input : inputs) {
|
||||||
if (isFileOrDir(input) && Files.isDirectory(Paths.get(input))) {
|
if (isFileOrDir(input) && Files.isDirectory(Paths.get(input))) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -30,8 +30,8 @@ import com.google.gwt.user.client.ui.Widget;
|
||||||
*/
|
*/
|
||||||
public final class GeoLocationGenerator implements GeneratorSource {
|
public final class GeoLocationGenerator implements GeneratorSource {
|
||||||
|
|
||||||
private static final String LON_REGEXP = "[+-]?[0-9]+(.[0-9]+)?";
|
private static final String LON_REGEXP = "[+-]?[0-9]+(?:.[0-9]+)?";
|
||||||
private static final String LAT_REGEXP = "[+-]?[0-9]+(.[0-9]+)?";
|
private static final String LAT_REGEXP = "[+-]?[0-9]+(?:.[0-9]+)?";
|
||||||
|
|
||||||
private Grid table;
|
private Grid table;
|
||||||
private final TextBox latitude = new TextBox();
|
private final TextBox latitude = new TextBox();
|
||||||
|
|
|
@ -109,7 +109,7 @@ public final class DecodeServlet extends HttpServlet {
|
||||||
HINTS_PURE.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
HINTS_PURE.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<String> blockedURLSubstrings;
|
private Collection<String> blockedURLSubstrings;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private DoSTracker destHostTracker;
|
private DoSTracker destHostTracker;
|
||||||
|
|
||||||
|
@ -155,11 +155,14 @@ public final class DecodeServlet extends HttpServlet {
|
||||||
|
|
||||||
// Remove any whitespace to sanitize; none is valid anyway
|
// Remove any whitespace to sanitize; none is valid anyway
|
||||||
imageURIString = WHITESPACE.matcher(imageURIString).replaceAll("");
|
imageURIString = WHITESPACE.matcher(imageURIString).replaceAll("");
|
||||||
for (CharSequence substring : blockedURLSubstrings) {
|
|
||||||
if (imageURIString.contains(substring)) {
|
if (!blockedURLSubstrings.isEmpty()) {
|
||||||
log.info("Disallowed URI " + imageURIString);
|
for (CharSequence substring : blockedURLSubstrings) {
|
||||||
errorResponse(request, response, "badurl");
|
if (imageURIString.contains(substring)) {
|
||||||
return;
|
log.info("Disallowed URI " + imageURIString);
|
||||||
|
errorResponse(request, response, "badurl");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +201,11 @@ public final class DecodeServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (destHostTracker.isBanned(imageURI.getHost())) {
|
||||||
|
errorResponse(request, response, "badurl");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
URL imageURL;
|
URL imageURL;
|
||||||
try {
|
try {
|
||||||
|
@ -215,12 +223,6 @@ public final class DecodeServlet extends HttpServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destHostTracker.isBanned(imageURL.getHost())) {
|
|
||||||
log.info("Temporarily not requesting from host: " + imageURIString);
|
|
||||||
errorResponse(request, response, "badurl");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
try {
|
try {
|
||||||
connection = (HttpURLConnection) imageURL.openConnection();
|
connection = (HttpURLConnection) imageURL.openConnection();
|
||||||
|
|
|
@ -34,7 +34,7 @@ public final class DoSFilterTestCase extends Assert {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.setRequestURI("/");
|
request.setRequestURI("/");
|
||||||
request.setRemoteAddr("1.2.3.4");
|
request.setRemoteAddr("1.2.3.4");
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
HttpServletResponse response = new MockHttpServletResponse();
|
||||||
DoSFilter filter = new DoSFilter();
|
DoSFilter filter = new DoSFilter();
|
||||||
filter.init(null);
|
filter.init(null);
|
||||||
for (int i = 0; i < DoSFilter.MAX_ACCESS_PER_TIME; i++) {
|
for (int i = 0; i < DoSFilter.MAX_ACCESS_PER_TIME; i++) {
|
||||||
|
|
|
@ -19,6 +19,8 @@ package com.google.zxing.web;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link LRUMap}.
|
* Tests {@link LRUMap}.
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +28,7 @@ public final class LRUMapTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLRU() {
|
public void testLRU() {
|
||||||
LRUMap<String,String> map = new LRUMap<>(2);
|
Map<String,String> map = new LRUMap<>(2);
|
||||||
map.put("foo", "bar");
|
map.put("foo", "bar");
|
||||||
map.put("bar", "baz");
|
map.put("bar", "baz");
|
||||||
assertEquals("bar", map.get("foo"));
|
assertEquals("bar", map.get("foo"));
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.springframework.mock.web.MockFilterChain;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,8 +35,8 @@ public final class WelcomeFilterTestCase extends Assert {
|
||||||
public void testRedirect() {
|
public void testRedirect() {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.setRequestURI("/");
|
request.setRequestURI("/");
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
HttpServletResponse response = new MockHttpServletResponse();
|
||||||
MockFilterChain chain = new MockFilterChain();
|
FilterChain chain = new MockFilterChain();
|
||||||
new WelcomeFilter().doFilter(request, response, chain);
|
new WelcomeFilter().doFilter(request, response, chain);
|
||||||
assertEquals(HttpServletResponse.SC_MOVED_PERMANENTLY, response.getStatus());
|
assertEquals(HttpServletResponse.SC_MOVED_PERMANENTLY, response.getStatus());
|
||||||
assertEquals("/w/decode.jspx", response.getHeader(HttpHeaders.LOCATION));
|
assertEquals("/w/decode.jspx", response.getHeader(HttpHeaders.LOCATION));
|
||||||
|
|
Loading…
Reference in a new issue