Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

public class Main {
    private static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    public static byte[] decodeB(byte[] bytes) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int i = 0;
        int len = bytes.length;
        while (i < len) {
            char[] four = new char[4];
            int j = 0;
            while (j < 4) {
                byte b = bytes[i++];
                if (b != '\r' || b != '\n')
                    four[j++] = (char) b;
            }
            int k;
            if (four[3] == '=') {
                if (four[2] == '=') {
                    k = 1;
                } else {
                    k = 2;
                }
            } else {
                k = 3;
            }
            int aux = 0;
            for (j = 0; j < 4; j++) {
                if (four[j] != '=') {
                    aux = aux | (chars.indexOf(four[j]) << (6 * (3 - j)));
                }
            }
            for (j = 0; j < k; j++) {
                out.write((aux >>> (8 * (2 - j))) & 0xFF);
            }
        }
        out.close();
        return out.toByteArray();
    }
}