import java.io.Console;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static java.nio.charset.StandardCharsets.UTF_8;

class Issue {
    public static void main(String... args) throws IOException {
        // [Console]::InputEncoding = [Console]::OutputEncoding = [Text.Encoding]::UTF8
        System.out.println(java.util.Arrays.toString(args));
        Console console = System.console();
        if(console != null) {
            // java '-Dfile.encoding=UTF-8' Issue.java
            System.out.print("Copy-paste and enter the following: `x\u20acx`: ");
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in, UTF_8));
            String line = in.readLine();
            print("interactive", line);
        } else {
            // Write-Output "x`u{20ac}x" | java '-Dfile.encoding=UTF-8' Issue.java
            String input = new String(System.in.readAllBytes(), UTF_8);
            print("piped", input);
        }
    }

    static void print(String prefix, String message) {
        System.out.println("%s: `%s` (%s)".formatted(prefix, message, message.codePoints().mapToObj(Integer::toHexString).toList()));
    }
} 