Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static BufferedReader displayQRCode(String app, String email, String secret) throws IOException {
        String command = createCommand(app, email, secret);
        Process exec = Runtime.getRuntime().exec(command);
        BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        return reader;
    }

    private static String createCommand(String app, String email, String secret) {
        StringBuilder builder = new StringBuilder();
        builder.append(app);
        builder.append(" otpauth://totp/");
        builder.append(email);
        builder.append("?secret=");
        builder.append(secret);
        return builder.toString();
    }
}