generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathqrcode.java
57 lines (45 loc) · 1.7 KB
/
qrcode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.org/license/UPL.
*/
//DEPS org.graalvm.python:python-language:24.2.0
//DEPS org.graalvm.python:python-launcher:24.2.0
//DEPS org.graalvm.python:python-resources:24.2.0
//DEPS org.graalvm.python:python-embedding:24.2.0
//DEPS org.graalvm.python:python-embedding-tools:24.2.0
//DEPS org.graalvm.python:jbang:24.2.0
//DEPS org.graalvm.truffle:truffle-runtime:24.2.0
//PIP qrcode==7.4.2
import org.graalvm.python.embedding.utils.GraalPyResources;
public class qrcode {
public static void main(String[] args) {
if (args.length != 1 || args[0].equals("-h") || args[0].equals("--help")) {
System.out.println("This tool takes only a single argument, the QR code data.");
return;
}
try (var context = GraalPyResources.contextBuilder().option("python.PythonHome", "").build()) {
QRCodeModule qrcodeModule = context.eval("python", "import qrcode; qrcode").as(QRCodeModule.class);
IO io = context.eval("python", "import io; io").as(IO.class);
QRCode qr = qrcodeModule.QRCode();
qr.add_data(args[0]);
StringIO f = io.StringIO();
qr.print_ascii(f);
String qrCodeString = f.getvalue();
System.out.println(qrCodeString);
}
}
public interface QRCodeModule {
QRCode QRCode();
}
public interface QRCode {
void add_data(String text);
void print_ascii(StringIO out);
}
public interface IO {
StringIO StringIO();
}
public interface StringIO {
String getvalue();
}
}