Barcode Reader CLI
Integration
Java
Java
brcli-example.config
1import java.io.BufferedReader;
2import java.io.IOException;
3import java.io.InputStreamReader;
4import java.io.File;
5
6public class brcli_example{
7
8 public static String implode(String separator, String[] data) {
9 StringBuilder sb = new StringBuilder();
10 for (int i = 0; i < data.length - 1; i++) {
11 //data.length - 1 => to not add separator at the end
12 if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on
13 sb.append(data[i]);
14 sb.append(separator);
15 }
16 }
17 sb.append(data[data.length - 1].trim());
18 return sb.toString();
19 }
20
21 public static void main(String []args) throws IOException {
22 boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
23 File myDir = new File(brcli_example.class.getProtectionDomain().getCodeSource().getLocation().getPath());
24
25 String[] cargs = {
26 (isWindows) ? ".\\BarcodeReaderCLI.exe" : "./BarcodeReaderCLI",
27 "-type=code128",
28 "https://wabr.inliteresearch.com/SampleImages/1d.pdf",
29 "@./brcli-example.config" // Additional options and sources in configuration file
30 };
31
32 String cmd = implode(" ", cargs);
33 ProcessBuilder builder = new ProcessBuilder();
34
35 if (isWindows) {
36 builder.command("cmd.exe", "/c", cmd);
37 } else {
38 builder.command("sh", "-c", cmd);
39 }
40 builder.directory(myDir);
41 builder.redirectErrorStream(true);
42 Process process = builder.start();
43 try (BufferedReader reader = new BufferedReader(
44 new InputStreamReader(process.getInputStream()))) {
45 String line;
46 while ((line = reader.readLine()) != null) {
47 System.out.println(line);
48 }
49 }
50 }
51}