*/
public static final ResultMetadataType BYTE_SEGMENTS = new ResultMetadataType();
+ /**
+ * Error correction level used, if applicable. The value type depends on the
+ * format, but is typically a String.
+ */
+ public static final ResultMetadataType ERROR_CORRECTION_LEVEL = new ResultMetadataType();
+
private ResultMetadataType() {
}
package com.google.zxing.common;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
import java.util.Vector;
/**
private final byte[] rawBytes;
private final String text;
private final Vector byteSegments;
+ private final ErrorCorrectionLevel ecLevel;
- public DecoderResult(byte[] rawBytes, String text, Vector byteSegments) {
+ public DecoderResult(byte[] rawBytes, String text, Vector byteSegments, ErrorCorrectionLevel ecLevel) {
if (rawBytes == null && text == null) {
throw new IllegalArgumentException();
}
this.rawBytes = rawBytes;
this.text = text;
this.byteSegments = byteSegments;
+ this.ecLevel = ecLevel;
}
public byte[] getRawBytes() {
return byteSegments;
}
+ public ErrorCorrectionLevel getECLevel() {
+ return ecLevel;
+ }
+
}
\ No newline at end of file
if (decoderResult.getByteSegments() != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
}
+ if (decoderResult.getECLevel() != null) {
+ result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
+ }
return result;
}
if (resultTrailer.length() > 0) {
result.append(resultTrailer.toString());
}
- return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments);
+ return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, null);
}
/**
if (decoderResult.getByteSegments() != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
}
+ if (decoderResult.getECLevel() != null) {
+ result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
+ }
results.addElement(result);
} catch (ReaderException re) {
// ignore and continue
throw ReaderException.getInstance();\r
}\r
}\r
- return new DecoderResult(null, result.toString(), null);\r
+ return new DecoderResult(null, result.toString(), null, null);\r
}\r
\r
/**\r
if (decoderResult.getByteSegments() != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
}
+ if (decoderResult.getECLevel() != null) {
+ result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
+ }
return result;
}
private DecodedBitStreamParser() {
}
- static DecoderResult decode(byte[] bytes, Version version) throws ReaderException {
+ static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel) throws ReaderException {
BitSource bits = new BitSource(bytes);
StringBuffer result = new StringBuffer();
CharacterSetECI currentCharacterSetECI = null;
}
} while (!mode.equals(Mode.TERMINATOR));
- return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments);
+ return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, ecLevel);
}
private static void decodeKanjiSegment(BitSource bits,
}\r
\r
// Decode the contents of that stream of bytes\r
- return DecodedBitStreamParser.decode(resultBytes, version);\r
+ return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);\r
}\r
\r
/**\r
builder.write(0xF2, 8);
builder.write(0xF3, 8);
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
- Version.getVersionForNumber(1)).getText();
+ Version.getVersionForNumber(1), null).getText();
assertEquals("\u00f1\u00f2\u00f3", result);
}
builder.write(0xA2, 8);
builder.write(0xA3, 8);
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
- Version.getVersionForNumber(1)).getText();
+ Version.getVersionForNumber(1), null).getText();
assertEquals("\uff61\uff62\uff63", result);
}
builder.write(0xA2, 8);
builder.write(0xA3, 8);
String result = DecodedBitStreamParser.decode(builder.toByteArray(),
- Version.getVersionForNumber(1)).getText();
+ Version.getVersionForNumber(1), null).getText();
assertEquals("\u00ed\u00f3\u00fa", result);
}