本文整理汇总了Java中com.google.zxing.FormatException.getFormatInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FormatException.getFormatInstance方法的具体用法?Java FormatException.getFormatInstance怎么用?Java FormatException.getFormatInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.FormatException
的用法示例。
在下文中一共展示了FormatException.getFormatInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DecodedNumeric
import com.google.zxing.FormatException; //导入方法依赖的package包/类
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;
}
示例2: decodeAnsiX12Segment
import com.google.zxing.FormatException; //导入方法依赖的package包/类
/**
* See ISO 16022:2006, 5.2.7
*/
private static void decodeAnsiX12Segment(BitSource bits,
StringBuilder result) throws FormatException {
// Three ANSI X12 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
int[] cValues = new int[3];
do {
// If there is only one byte left then it will be encoded as ASCII
if (bits.available() == 8) {
return;
}
int firstByte = bits.readBits(8);
if (firstByte == 254) { // Unlatch codeword
return;
}
parseTwoBytes(firstByte, bits.readBits(8), cValues);
for (int i = 0; i < 3; i++) {
int cValue = cValues[i];
if (cValue == 0) { // X12 segment terminator <CR>
result.append('\r');
} else if (cValue == 1) { // X12 segment separator *
result.append('*');
} else if (cValue == 2) { // X12 sub-element separator >
result.append('>');
} else if (cValue == 3) { // space
result.append(' ');
} else if (cValue < 14) { // 0 - 9
result.append((char) (cValue + 44));
} else if (cValue < 40) { // A - Z
result.append((char) (cValue + 51));
} else {
throw FormatException.getFormatInstance();
}
}
} while (bits.available() > 0);
}
示例3: decodeCodewords
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures)
throws FormatException, ChecksumException {
if (codewords.length == 0) {
throw FormatException.getFormatInstance();
}
int numECCodewords = 1 << (ecLevel + 1);
int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);
verifyCodewordCount(codewords, numECCodewords);
DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, String.valueOf
(ecLevel));
decoderResult.setErrorsCorrected(Integer.valueOf(correctedErrorsCount));
decoderResult.setErasures(Integer.valueOf(erasures.length));
return decoderResult;
}
示例4: decodeBase256Segment
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static void decodeBase256Segment(BitSource bits, StringBuilder result,
Collection<byte[]> byteSegments) throws
FormatException {
int count;
int codewordPosition = bits.getByteOffset() + 1;
int codewordPosition2 = codewordPosition + 1;
int d1 = unrandomize255State(bits.readBits(8), codewordPosition);
if (d1 == 0) {
count = bits.available() / 8;
codewordPosition = codewordPosition2;
} else if (d1 < 250) {
count = d1;
codewordPosition = codewordPosition2;
} else {
codewordPosition = codewordPosition2 + 1;
count = ((d1 - 249) * 250) + unrandomize255State(bits.readBits(8), codewordPosition2);
}
if (count < 0) {
throw FormatException.getFormatInstance();
}
byte[] bytes = new byte[count];
int i = 0;
codewordPosition2 = codewordPosition;
while (i < count) {
if (bits.available() < 8) {
throw FormatException.getFormatInstance();
}
codewordPosition = codewordPosition2 + 1;
bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition2);
i++;
codewordPosition2 = codewordPosition;
}
byteSegments.add(bytes);
try {
result.append(new String(bytes, "ISO8859_1"));
} catch (UnsupportedEncodingException uee) {
throw new IllegalStateException("Platform does not support required encoding: " + uee);
}
}
示例5: getProvisionalVersionForDimension
import com.google.zxing.FormatException; //导入方法依赖的package包/类
public static Version getProvisionalVersionForDimension(int dimension) throws FormatException {
if (dimension % 4 != 1) {
throw FormatException.getFormatInstance();
}
try {
return getVersionForNumber((dimension - 17) / 4);
} catch (IllegalArgumentException e) {
throw FormatException.getFormatInstance();
}
}
示例6: getProvisionalVersionForDimension
import com.google.zxing.FormatException; //导入方法依赖的package包/类
/**
* <p>Deduces version information purely from QR Code dimensions.</p>
*
* @param dimension dimension in modules
* @return Version for a QR Code of that dimension
* @throws FormatException if dimension is not 1 mod 4
*/
public static Version getProvisionalVersionForDimension(int dimension) throws FormatException {
if (dimension % 4 != 1) {
throw FormatException.getFormatInstance();
}
try {
return getVersionForNumber((dimension - 17) / 4);
} catch (IllegalArgumentException ignored) {
throw FormatException.getFormatInstance();
}
}
示例7: decodeBase256Segment
import com.google.zxing.FormatException; //导入方法依赖的package包/类
/**
* See ISO 16022:2006, 5.2.9 and Annex B, B.2
*/
private static void decodeBase256Segment(BitSource bits,
StringBuilder result,
Collection<byte[]> byteSegments)
throws FormatException {
// Figure out how long the Base 256 Segment is.
int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
int count;
if (d1 == 0) { // Read the remainder of the symbol
count = bits.available() / 8;
} else if (d1 < 250) {
count = d1;
} else {
count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
}
// We're seeing NegativeArraySizeException errors from users.
if (count < 0) {
throw FormatException.getFormatInstance();
}
byte[] bytes = new byte[count];
for (int i = 0; i < count; i++) {
// Have seen this particular error in the wild, such as at
// http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
if (bits.available() < 8) {
throw FormatException.getFormatInstance();
}
bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
}
byteSegments.add(bytes);
try {
result.append(new String(bytes, "ISO8859_1"));
} catch (UnsupportedEncodingException uee) {
throw new IllegalStateException("Platform does not support required encoding: " + uee);
}
}
示例8: decodeByteSegment
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static void decodeByteSegment(BitSource bits,
StringBuilder result,
int count,
CharacterSetECI currentCharacterSetECI,
Collection<byte[]> byteSegments,
Map<DecodeHintType,?> hints) throws FormatException {
// Don't crash trying to read more bits than we have available.
if (8 * count > bits.available()) {
throw FormatException.getFormatInstance();
}
byte[] readBytes = new byte[count];
for (int i = 0; i < count; i++) {
readBytes[i] = (byte) bits.readBits(8);
}
String encoding;
if (currentCharacterSetECI == null) {
// The spec isn't clear on this mode; see
// section 6.4.5: t does not say which encoding to assuming
// upon decoding. I have seen ISO-8859-1 used as well as
// Shift_JIS -- without anything like an ECI designator to
// give a hint.
encoding = StringUtils.guessEncoding(readBytes, hints);
} else {
encoding = currentCharacterSetECI.name();
}
try {
result.append(new String(readBytes, encoding));
} catch (UnsupportedEncodingException ignored) {
throw FormatException.getFormatInstance();
}
byteSegments.add(readBytes);
}
示例9: readFormatInformation
import com.google.zxing.FormatException; //导入方法依赖的package包/类
/**
* <p>Reads format information from one of its two locations within the QR Code.</p>
*
* @return {@link FormatInformation} encapsulating the QR Code's format info
* @throws FormatException if both format information locations cannot be parsed as
* the valid encoding of format information
*/
FormatInformation readFormatInformation() throws FormatException {
if (parsedFormatInfo != null) {
return parsedFormatInfo;
}
// Read top-left format info bits
int formatInfoBits1 = 0;
for (int i = 0; i < 6; i++) {
formatInfoBits1 = copyBit(i, 8, formatInfoBits1);
}
// .. and skip a bit in the timing pattern ...
formatInfoBits1 = copyBit(7, 8, formatInfoBits1);
formatInfoBits1 = copyBit(8, 8, formatInfoBits1);
formatInfoBits1 = copyBit(8, 7, formatInfoBits1);
// .. and skip a bit in the timing pattern ...
for (int j = 5; j >= 0; j--) {
formatInfoBits1 = copyBit(8, j, formatInfoBits1);
}
// Read the top-right/bottom-left pattern too
int dimension = bitMatrix.getHeight();
int formatInfoBits2 = 0;
int jMin = dimension - 7;
for (int j = dimension - 1; j >= jMin; j--) {
formatInfoBits2 = copyBit(8, j, formatInfoBits2);
}
for (int i = dimension - 8; i < dimension; i++) {
formatInfoBits2 = copyBit(i, 8, formatInfoBits2);
}
parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2);
if (parsedFormatInfo != null) {
return parsedFormatInfo;
}
throw FormatException.getFormatInstance();
}
示例10: maybeReturnResult
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static Result maybeReturnResult(Result result) throws FormatException {
String text = result.getText();
if (text.charAt(0) == '0') {
return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
} else {
throw FormatException.getFormatInstance();
}
}
示例11: decode
import com.google.zxing.FormatException; //导入方法依赖的package包/类
public DecoderResult decode(BitMatrix bits,
Map<DecodeHintType,?> hints) throws FormatException, ChecksumException {
BitMatrixParser parser = new BitMatrixParser(bits);
byte[] codewords = parser.readCodewords();
correctErrors(codewords, 0, 10, 10, ALL);
int mode = codewords[0] & 0x0F;
byte[] datawords;
switch (mode) {
case 2:
case 3:
case 4:
correctErrors(codewords, 20, 84, 40, EVEN);
correctErrors(codewords, 20, 84, 40, ODD);
datawords = new byte[94];
break;
case 5:
correctErrors(codewords, 20, 68, 56, EVEN);
correctErrors(codewords, 20, 68, 56, ODD);
datawords = new byte[78];
break;
default:
throw FormatException.getFormatInstance();
}
System.arraycopy(codewords, 0, datawords, 0, 10);
System.arraycopy(codewords, 20, datawords, 10, datawords.length - 10);
return DecodedBitStreamParser.decode(datawords, mode);
}
示例12: decodeNumericSegment
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static void decodeNumericSegment(BitSource bits,
StringBuilder result,
int count) throws FormatException {
// Read three digits at a time
while (count >= 3) {
// Each 10 bits encodes three digits
if (bits.available() < 10) {
throw FormatException.getFormatInstance();
}
int threeDigitsBits = bits.readBits(10);
if (threeDigitsBits >= 1000) {
throw FormatException.getFormatInstance();
}
result.append(toAlphaNumericChar(threeDigitsBits / 100));
result.append(toAlphaNumericChar((threeDigitsBits / 10) % 10));
result.append(toAlphaNumericChar(threeDigitsBits % 10));
count -= 3;
}
if (count == 2) {
// Two digits left over to read, encoded in 7 bits
if (bits.available() < 7) {
throw FormatException.getFormatInstance();
}
int twoDigitsBits = bits.readBits(7);
if (twoDigitsBits >= 100) {
throw FormatException.getFormatInstance();
}
result.append(toAlphaNumericChar(twoDigitsBits / 10));
result.append(toAlphaNumericChar(twoDigitsBits % 10));
} else if (count == 1) {
// One digit left over to read
if (bits.available() < 4) {
throw FormatException.getFormatInstance();
}
int digitBits = bits.readBits(4);
if (digitBits >= 10) {
throw FormatException.getFormatInstance();
}
result.append(toAlphaNumericChar(digitBits));
}
}
示例13: decodeExtended
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static String decodeExtended(CharSequence encoded) throws FormatException {
int length = encoded.length();
StringBuilder decoded = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = encoded.charAt(i);
if (c == '+' || c == '$' || c == '%' || c == '/') {
char next = encoded.charAt(i + 1);
char decodedChar = '\0';
switch (c) {
case '+':
// +A to +Z map to a to z
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next + 32);
} else {
throw FormatException.getFormatInstance();
}
break;
case '$':
// $A to $Z map to control codes SH to SB
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next - 64);
} else {
throw FormatException.getFormatInstance();
}
break;
case '%':
// %A to %E map to control codes ESC to US
if (next >= 'A' && next <= 'E') {
decodedChar = (char) (next - 38);
} else if (next >= 'F' && next <= 'W') {
decodedChar = (char) (next - 11);
} else {
throw FormatException.getFormatInstance();
}
break;
case '/':
// /A to /O map to ! to , and /Z maps to :
if (next >= 'A' && next <= 'O') {
decodedChar = (char) (next - 32);
} else if (next == 'Z') {
decodedChar = ':';
} else {
throw FormatException.getFormatInstance();
}
break;
}
decoded.append(decodedChar);
// bump up i again since we read two characters
i++;
} else {
decoded.append(c);
}
}
return decoded.toString();
}
示例14: readVersion
import com.google.zxing.FormatException; //导入方法依赖的package包/类
/**
* <p>Reads version information from one of its two locations within the QR Code.</p>
*
* @return {@link Version} encapsulating the QR Code's version
* @throws FormatException if both version information locations cannot be parsed as
* the valid encoding of version information
*/
Version readVersion() throws FormatException {
if (parsedVersion != null) {
return parsedVersion;
}
int dimension = bitMatrix.getHeight();
int provisionalVersion = (dimension - 17) / 4;
if (provisionalVersion <= 6) {
return Version.getVersionForNumber(provisionalVersion);
}
// Read top-right version info: 3 wide by 6 tall
int versionBits = 0;
int ijMin = dimension - 11;
for (int j = 5; j >= 0; j--) {
for (int i = dimension - 9; i >= ijMin; i--) {
versionBits = copyBit(i, j, versionBits);
}
}
Version theParsedVersion = Version.decodeVersionInformation(versionBits);
if (theParsedVersion != null && theParsedVersion.getDimensionForVersion() == dimension) {
parsedVersion = theParsedVersion;
return theParsedVersion;
}
// Hmm, failed. Try bottom left: 6 wide by 3 tall
versionBits = 0;
for (int i = 5; i >= 0; i--) {
for (int j = dimension - 9; j >= ijMin; j--) {
versionBits = copyBit(i, j, versionBits);
}
}
theParsedVersion = Version.decodeVersionInformation(versionBits);
if (theParsedVersion != null && theParsedVersion.getDimensionForVersion() == dimension) {
parsedVersion = theParsedVersion;
return theParsedVersion;
}
throw FormatException.getFormatInstance();
}
示例15: decodeExtended
import com.google.zxing.FormatException; //导入方法依赖的package包/类
private static String decodeExtended(CharSequence encoded) throws FormatException {
int length = encoded.length();
StringBuilder decoded = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = encoded.charAt(i);
if (c >= 'a' && c <= 'd') {
if (i >= length - 1) {
throw FormatException.getFormatInstance();
}
char next = encoded.charAt(i + 1);
char decodedChar = '\0';
switch (c) {
case 'd':
// +A to +Z map to a to z
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next + 32);
} else {
throw FormatException.getFormatInstance();
}
break;
case 'a':
// $A to $Z map to control codes SH to SB
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next - 64);
} else {
throw FormatException.getFormatInstance();
}
break;
case 'b':
if (next >= 'A' && next <= 'E') {
// %A to %E map to control codes ESC to USep
decodedChar = (char) (next - 38);
} else if (next >= 'F' && next <= 'J') {
// %F to %J map to ; < = > ?
decodedChar = (char) (next - 11);
} else if (next >= 'K' && next <= 'O') {
// %K to %O map to [ \ ] ^ _
decodedChar = (char) (next + 16);
} else if (next >= 'P' && next <= 'S') {
// %P to %S map to { | } ~
decodedChar = (char) (next + 43);
} else if (next >= 'T' && next <= 'Z') {
// %T to %Z all map to DEL (127)
decodedChar = 127;
} else {
throw FormatException.getFormatInstance();
}
break;
case 'c':
// /A to /O map to ! to , and /Z maps to :
if (next >= 'A' && next <= 'O') {
decodedChar = (char) (next - 32);
} else if (next == 'Z') {
decodedChar = ':';
} else {
throw FormatException.getFormatInstance();
}
break;
}
decoded.append(decodedChar);
// bump up i again since we read two characters
i++;
} else {
decoded.append(c);
}
}
return decoded.toString();
}