42.4. 使用 Java DSL
首先,您必须初始化 barcode 数据随机类。您可以使用默认构造器或参数之一(请参阅 JavaDoc)。默认值为:
| 参数 | 默认值 |
|---|---|
| 镜像类型(BarcodeImageType) | PNG |
| width | 100 px |
| height | 100 px |
| 编码 | UTF-8 |
| Barcode 格式(BarcodeFormat) | QR-Code |
// QR-Code default DataFormat code = new BarcodeDataFormat();
// QR-Code default
DataFormat code = new BarcodeDataFormat();
如果要使用 zxing hints,您可以使用 BarcodeDataFormat 实例的 'addToHintMap' 方法:
code.addToHintMap(DecodeHintType.TRY_HARDER, Boolean.true);
code.addToHintMap(DecodeHintType.TRY_HARDER, Boolean.true);
有关可能的提示,请参阅 xzing 文档。
42.4.1. Marshalling 复制链接链接已复制到粘贴板!
from("direct://code")
.marshal(code)
.to("file://barcode_out");
from("direct://code")
.marshal(code)
.to("file://barcode_out");
您可以使用以下方法调用测试类的路由:
template.sendBody("direct://code", "This is a testmessage!");
template.sendBody("direct://code", "This is a testmessage!");
您可以在此镜像的 'barcode_out' 文件夹中找到:
42.4.2. unmarshalling 复制链接链接已复制到粘贴板!
unmarshaller 是通用的。对于 unmarshalling,您可以使用任何 BarcodeDataFormat 实例。如果您有两个实例,一个用于(生成)QR-Code,另一个用于 PDF417,则它将不会被使用。
from("file://barcode_in?noop=true")
.unmarshal(code) // for unmarshalling, the instance doesn't matter
.to("mock:out");
from("file://barcode_in?noop=true")
.unmarshal(code) // for unmarshalling, the instance doesn't matter
.to("mock:out");
如果您将上面的 QR-Code 镜像粘贴到"barcode_in"文件夹中,您应该在模拟中找到 'This is a testmessage!'。您可以将 barcode 数据格式找到为标头变量:
| 名称 | 类型 | 描述 |
|---|---|---|
| BarcodeFormat | 字符串 | com.google.zxing.BarcodeFormat 的值。 |