This example shows how to parse a Swiss QR Code into a QrInvoice object.

import ch.codeblock.qrinvoice.QrInvoiceCodeScanner;
import ch.codeblock.qrinvoice.model.ParseException;
import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.validation.ValidationException;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;
import ch.codeblock.qrinvoice.qrcode.DecodeException;

import java.io.InputStream;
import java.math.BigDecimal;

// ...


// either provide an input stream or a byte array
final InputStream imageInputStream = ...;

try {
    // this option uses the default QR Code library and performs default scanning efforts
    final QrCodeReaderOptions defaultOption = new QrCodeReaderOptions(ScanningEffortLevel.DEFAULT, QrCodeLibrary.DEFAULT);

    // You may however increase scanning efforts by choosing level "HARDER", which may result in much slower operations but higher detection rate
    // new QrCodeReaderOptions(ScanningEffortLevel.HARDER, QrCodeLibrary.DEFAULT);

    // you may also choose to use BoofCV in addition to ZXing using any available ScanningEffortLevel combination
    // new QrCodeReaderOptions(ScanningEffortLevel.DEFAULT, QrCodeLibrary.ZXING, QrCodeLibrary.BOOFCV);
    // new QrCodeReaderOptions(ScanningEffortLevel.HARDER, QrCodeLibrary.ZXING, QrCodeLibrary.BOOFCV);

    final QrInvoice qrInvoice = QrInvoiceCodeScanner.create(defaultOption).scan(imageInputStream);

    // access QR-Invoice structure
    final BigDecimal amount = qrInvoice.getPaymentAmountInformation().getAmount();

    // ...
} catch (DecodeException e) {
    // decoding error handling - e.g. qr code could be found in the given image
} catch (ParseException e) {
    // parsing exception handling
}

Instead of only scanning the QR Code it is possible to validate it just by calling the scanAndValidate method.

try {
    final QrInvoice qrInvoice = QrInvoiceCodeScanner.create().scanAndValidate(imageInputStream);

    // access QR-Invoice structure
    final BigDecimal amount = qrInvoice.getPaymentAmountInformation().getAmount();

    // ...
} catch (DecodeException e) {
    // decoding error handling - e.g. qr code could be found in the given image
} catch (ParseException e) {
    // parsing exception handling
} catch (ValidationException e) {
    final ValidationResult validationResult = e.getValidationResult();
    // ...
}

Please refer to How to Validate a QrInvoice Object for more information on the ValidationResult