Search in sources :

Example 41 with BASE64Decoder

use of sun.misc.BASE64Decoder in project pmph by BCSquad.

the class SsoHelperTest method jxBase64.

@Test
public void jxBase64() {
    String JSONResponse = "eyJzaWduIjoiYXhUYUExOFp0c0FKNjBJWG1KN3VLcnIzRGc2QWI0OFhrdWhzd005UktOWmpsTHlrQlhUeFRiWGVndmhybi81WStNUmxYNTM2MFlUS2VSYmZKbkVpYzBhTDlhR3B3cVp1WEhub213Y2lnNm44M3lLOFdjc1VhQ2dQcVB4TkhCSElKL1g2bjJwM1ZKL3pDTW1PNmFtdjVsOUVGdlJVc3dxMmFiY3VGUmVIdWVEcDVEaWtuUVZucDZRRTNSelBTWTVCck01eDFKY1JuUWdpblhrUDRoazBETDdoNnVsaTlyNmFodTB5YWRiNEpkellCT1RrdGh1WTRRWTc3REhTNUtrbUttRitYS1VTcTN6UWJnRWZOMlg0REhpTllsL0lsU3ZRS2xKNHY5MHJrUEx1a2xuNW1hK1oyVytPMmFQbDFKMjVNL0RUdjBwSjFValRrdDRUWVRQUHRBPT0iLCJhc3NlcnRpb24iOnsibm90QmVmb3JlIjoxNTI5Mzc1MjA4OTM3LCJhcHBOYW1lIjoi5Lq65Y2rZeaVmSIsIl9sb2NhbFVzZXJuYW1lIjoiZ3kiLCJhcHBJZCI6IjI0IiwiX2xvY2FsUGFzc3dvcmQiOiJHdXlhbjc1MjEiLCJhcHBMb2dpblBhc3MiOiJHdXlhbjc1MjEiLCJ1c2VySWQiOiJneSIsIm5vdEFmdGVyIjoxNTI5Mzc1ODA4OTM3LCJzc29UR1QiOiJleUpUU1VkT0lqb2lhbmRIVDJKV2VUSmpabXBWVVhBMFFWQXlWR1pIYTI5TlMxRk5QU0lzSWxSSFZDSTZJbVY1U21waU1qVnJZVmhTY0dJeU5HbFBibk5wV1cxV2JtRlhOVlZoVnpGc1NXcHZlRTVVU1RWTmVtTXdUbFJOTUU1VVp6Rk1RMHB0WVZjMWFHSkdVbkJpVjFWcFQycEZNVTFxYTNwT2VtZDRUWHBSTVU5RVZYTkpia3BzWWxjNU1GcFZhSFpqTTFGcFQybEplRTFxVVhWTlZFa3pUR3BGZVU1NU5IaFBWR2RwWmxOM2FWcEhSakJaVTBrMlpYbEthR1JZVW05VVIxWXlXbGQzYVU5cFNYbEphWGRwV1ZoV01HRkZOV2hpVjFWcFQybE1iR28yVUd0MU5sUnZjbkZVYjNJMFJXbE1RMHBvWkZoU2IxWkliSGRhVTBrMlNXNUNhR016VGpOaU0wcHJTV2wzYVdKSE9XNWhWelZQV1ZjeGJFbHFiMmxhTTJ0cFpsZ3dQU0o5IiwiYXBwTG9naW5JRCI6Imd5In19";
    BASE64Decoder decode = new BASE64Decoder();
    String json = null;
    try {
        json = new String(decode.decodeBuffer(JSONResponse));
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(json);
}
Also used : IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 42 with BASE64Decoder

use of sun.misc.BASE64Decoder in project PorkBot by DaMatrix.

the class CommandMcIcon method execute.

@Override
public void execute(MessageReceivedEvent evt, String[] args, String message) {
    try {
        if (args.length < 2 || args[1].isEmpty()) {
            sendErrorMessage(evt.getTextChannel(), "IP isn't given!");
            return;
        }
        MCPing.McPing ping = null;
        String[] ipPort = args[1].split(":");
        if (ipPort.length == 1) {
            ping = MCPing.pingPc(ipPort[0], 25565, false);
        } else if (ipPort.length == 2) {
            try {
                ping = MCPing.pingPc(ipPort[0], Integer.parseInt(ipPort[1]), false);
            } catch (NumberFormatException e) {
                MessageUtils.sendMessage("Error getting server info: `java.lang.NumberFormatException`", evt.getTextChannel());
                return;
            }
        } else {
            MessageUtils.sendMessage("Unable to parse server ip!", evt.getTextChannel());
            return;
        }
        EmbedBuilder builder = new EmbedBuilder();
        if (ping.status) {
            // server's online
            builder.setColor(Color.GREEN);
            builder.setTitle("**" + ipPort[0] + (ipPort.length == 2 ? ":" + ipPort[1] : "") + "**'s favicon");
            String[] parts = ping.favicon.split("\\,");
            String imageString = parts[1];
            byte[] imageByte;
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);
            builder.setThumbnail("attachment://image.png");
            MessageUtils.sendImage(builder, imageByte, "image.png", evt.getTextChannel());
            return;
        } else {
            // server's offline
            builder.setColor(Color.RED);
            builder.addField("**" + args[1] + "**", "***OFFLINE***", false);
        }
        MessageUtils.sendMessage(builder, evt.getTextChannel());
    } catch (IOException e) {
        MessageUtils.sendException(e, evt);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MCPing(net.daporkchop.porkbot.util.mcpinger.MCPing) IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder)

Example 43 with BASE64Decoder

use of sun.misc.BASE64Decoder in project PorkBot by DaMatrix.

the class CommandMcPing method execute.

@Override
public void execute(MessageReceivedEvent evt, String[] args, String message) {
    try {
        if (args.length < 2 || args[1].isEmpty()) {
            sendErrorMessage(evt.getTextChannel(), "IP isn't given!");
            return;
        }
        MCPing.McPing ping = null;
        String[] ipPort = args[1].split(":");
        if (ipPort.length == 1) {
            ping = MCPing.pingPc(ipPort[0], 25565, true);
        } else if (ipPort.length == 2) {
            try {
                ping = MCPing.pingPc(ipPort[0], Integer.parseInt(ipPort[1]), true);
            } catch (NumberFormatException e) {
                MessageUtils.sendMessage("Error getting server info: `java.lang.NumberFormatException`", evt.getTextChannel());
                return;
            }
        } else {
            MessageUtils.sendMessage("Unable to parse server ip!", evt.getTextChannel());
            return;
        }
        EmbedBuilder builder = new EmbedBuilder();
        if (ping.status) {
            // server's online
            builder.setColor(Color.GREEN);
            String[] parts = ping.favicon.split("\\,");
            String imageString = parts[1];
            byte[] imageByte;
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);
            builder.setThumbnail("attachment://image.png");
            builder.addField("**" + args[1] + "**", "Status: ***ONLINE***", false);
            builder.addField("Ping:", ping.ping, false);
            builder.addField("Version:", ping.version, false);
            builder.addField("Players:", ping.players, false);
            builder.addField("MOTD:", TextFormat.clean(ping.motd), false);
            builder.setAuthor("PorkBot", "http://www.daporkchop.net/porkbot", "https://cdn.discordapp.com/avatars/226975061880471552/a_195cf606ffbe9bd5bf1e8764c711253c.gif");
            MessageUtils.sendImage(builder, imageByte, "image.png", evt.getTextChannel());
            return;
        } else {
            // server's offline
            builder.setColor(Color.RED);
            builder.addField("**" + args[1] + "**", "Status: ***OFFLINE***", false);
        }
        MessageUtils.sendMessage(builder, evt.getTextChannel());
    } catch (IOException e) {
        MessageUtils.sendException(e, evt);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MCPing(net.daporkchop.porkbot.util.mcpinger.MCPing) IOException(java.io.IOException) BASE64Decoder(sun.misc.BASE64Decoder)

Example 44 with BASE64Decoder

use of sun.misc.BASE64Decoder in project notes by KevinBlandy.

the class Demo method test1.

// ����
public static String test1() throws UnsupportedEncodingException, IOException {
    BASE64Decoder de = new BASE64Decoder();
    byte[] s = de.decodeBuffer(test());
    return new String(s, "utf-8");
}
Also used : BASE64Decoder(sun.misc.BASE64Decoder)

Aggregations

BASE64Decoder (sun.misc.BASE64Decoder)44 IOException (java.io.IOException)23 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 OutputStream (java.io.OutputStream)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JSONObject (com.alibaba.fastjson.JSONObject)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 BASE64Encoder (sun.misc.BASE64Encoder)4 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)3 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 KeyFactory (java.security.KeyFactory)3 CertificateException (java.security.cert.CertificateException)3 Map (java.util.Map)3 Cipher (javax.crypto.Cipher)3