package com.yutou.qqbot.utlis;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;

public class Base64Tools {
    public static String encode(String str) {
        return java.util.Base64.getEncoder().encodeToString(str.getBytes());
    }

    public static String decode(String str) {
        return new String(java.util.Base64.getDecoder().decode(str));
    }

    public static String encode(byte[] bytes) {
        return java.util.Base64.getEncoder().encodeToString(bytes);
    }

    public static String encode(File file) {
        try {
            byte[] fileContent = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
            return encode(fileContent);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
    }
}
