/*
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hudson.remoting;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

/**
 * This class provides encode/decode for RFC 2045 Base64 as
 * defined by RFC 2045, N. Freed and N. Borenstein.
 * RFC 2045: Multipurpose Internet Mail Extensions (MIME)
 * Part One: Format of Internet Message Bodies. Reference
 * 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
 * This class is used by XML Schema binary format validation
 *
 * This implementation does not encode/decode streaming
 * data. You need the data that you will encode/decode
 * already on a byte arrray.
 *
 * @author Jeffrey Rodriguez
 * @author Sandy Gao
 * @version $Id: Base64.java,v 1.4 2007/07/19 04:38:32 ofung Exp $
 * @deprecated Use {@link java.util.Base64} instead
 */
@Deprecated
public final class  Base64 {

    static private final int  BASELENGTH         = 128;
    static private final int  LOOKUPLENGTH       = 64;
    static private final char PAD                = '=';
    static final private byte [] base64Alphabet        = new byte[BASELENGTH];
    static final private char [] lookUpBase64Alphabet  = new char[LOOKUPLENGTH];

    static {

        for (int i = 0; i < BASELENGTH; ++i) {
            base64Alphabet[i] = -1;
        }
        for (int i = 'Z'; i >= 'A'; i--) {
            base64Alphabet[i] = (byte) (i-'A');
        }
        for (int i = 'z'; i>= 'a'; i--) {
            base64Alphabet[i] = (byte) ( i-'a' + 26);
        }

        for (int i = '9'; i >= '0'; i--) {
            base64Alphabet[i] = (byte) (i-'0' + 52);
        }

        base64Alphabet['+']  = 62;
        base64Alphabet['/']  = 63;

        for (int i = 0; i<=25; i++)
            lookUpBase64Alphabet[i] = (char)('A'+i);

        for (int i = 26,  j = 0; i<=51; i++, j++)
            lookUpBase64Alphabet[i] = (char)('a'+ j);

        for (int i = 52,  j = 0; i<=61; i++, j++)
            lookUpBase64Alphabet[i] = (char)('0' + j);
        lookUpBase64Alphabet[62] = (char)'+';
        lookUpBase64Alphabet[63] = (char)'/';

    }

    protected static boolean isWhiteSpace(char octect) {
        return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
    }

    protected static boolean isPad(char octect) {
        return (octect == PAD);
    }

    protected static boolean isData(char octect) {
        return (octect < BASELENGTH && base64Alphabet[octect] != -1);
    }

    protected static boolean isBase64(char octect) {
        return (isWhiteSpace(octect) || isPad(octect) || isData(octect));
    }

    /**
     * Encodes hex octects into Base64
     *
     * @param binaryData Array containing binaryData
     * @return Encoded Base64 array. {@code null} if the input is null
     */
    @Nullable
    public static String encode(byte[] binaryData) {

        if (binaryData == null)
            return null;

        return java.util.Base64.getEncoder().encodeToString(binaryData);
    }

    /**
     * Decodes Base64 data into octects
     *
     * @param encoded string containing Base64 data
     * @return Array containing decoded data. {@code null} if the data cannot be decoded.
     */
    @CheckForNull
    @SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
            justification = "Null arrays are the part of the library API")
    public static byte[] decode(String encoded) {

        if (encoded == null)
            return null;

        return java.util.Base64.getDecoder().decode(encoded);
    }

    /**
     * remove WhiteSpace from MIME containing encoded Base64 data.
     *
     * @param data  the byte array of base64 data (with WS)
     * @return      the new length
     */
    protected static int removeWhiteSpace(char[] data) {
        if (data == null)
            return 0;

        // count characters that's not whitespace
        int newSize = 0;
        int len = data.length;
        for (int i = 0; i < len; i++) {
            if (!isWhiteSpace(data[i]))
                data[newSize++] = data[i];
        }
        return newSize;
    }
}

@@ -649,68 +649,8 @@
 g;%0A%0A
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;%0A%0A
 impo
@@ -1434,1728 +1434,8 @@
  %7B%0A%0A
-    static private final int  BASELENGTH         = 128;%0A    static private final int  LOOKUPLENGTH       = 64;%0A    static private final char PAD                = '=';%0A    static final private byte %5B%5D base64Alphabet        = new byte%5BBASELENGTH%5D;%0A    static final private char %5B%5D lookUpBase64Alphabet  = new char%5BLOOKUPLENGTH%5D;%0A%0A    static %7B%0A%0A        for (int i = 0; i %3C BASELENGTH; ++i) %7B%0A            base64Alphabet%5Bi%5D = -1;%0A        %7D%0A        for (int i = 'Z'; i %3E= 'A'; i--) %7B%0A            base64Alphabet%5Bi%5D = (byte) (i-'A');%0A        %7D%0A        for (int i = 'z'; i%3E= 'a'; i--) %7B%0A            base64Alphabet%5Bi%5D = (byte) ( i-'a' + 26);%0A        %7D%0A%0A        for (int i = '9'; i %3E= '0'; i--) %7B%0A            base64Alphabet%5Bi%5D = (byte) (i-'0' + 52);%0A        %7D%0A%0A        base64Alphabet%5B'+'%5D  = 62;%0A        base64Alphabet%5B'/'%5D  = 63;%0A%0A        for (int i = 0; i%3C=25; i++)%0A            lookUpBase64Alphabet%5Bi%5D = (char)('A'+i);%0A%0A        for (int i = 26,  j = 0; i%3C=51; i++, j++)%0A            lookUpBase64Alphabet%5Bi%5D = (char)('a'+ j);%0A%0A        for (int i = 52,  j = 0; i%3C=61; i++, j++)%0A            lookUpBase64Alphabet%5Bi%5D = (char)('0' + j);%0A        lookUpBase64Alphabet%5B62%5D = (char)'+';%0A        lookUpBase64Alphabet%5B63%5D = (char)'/';%0A%0A    %7D%0A%0A    protected static boolean isWhiteSpace(char octect) %7B%0A        return (octect == 0x20 %7C%7C octect == 0xd %7C%7C octect == 0xa %7C%7C octect == 0x9);%0A    %7D%0A%0A    protected static boolean isPad(char octect) %7B%0A        return (octect == PAD);%0A    %7D%0A%0A    protected static boolean isData(char octect) %7B%0A        return (octect %3C BASELENGTH && base64Alphabet%5Boctect%5D != -1);%0A    %7D%0A%0A    protected static boolean isBase64(char octect) %7B%0A        return (isWhiteSpace(octect) %7C%7C isPad(octect) %7C%7C isData(octect));%0A    %7D%0A%0A
     
@@ -2049,149 +2049,8 @@
 ull%0A
-    @SuppressFBWarnings(value = %22PZLA_PREFER_ZERO_LENGTH_ARRAYS%22,%0A            justification = %22Null arrays are the part of the library API%22)%0A
     
@@ -2222,568 +2222,7 @@
    %7D
-%0A%0A    /**%0A     * remove WhiteSpace from MIME containing encoded Base64 data.%0A     *%0A     * @param data  the byte array of base64 data (with WS)%0A     * @return      the new length%0A     */%0A    protected static int removeWhiteSpace(char%5B%5D data) %7B%0A        if (data == null)%0A            return 0;%0A%0A        // count characters that's not whitespace%0A        int newSize = 0;%0A        int len = data.length;%0A        for (int i = 0; i %3C len; i++) %7B%0A            if (!isWhiteSpace(data%5Bi%5D))%0A                data%5BnewSize++%5D = data%5Bi%5D;%0A        %7D%0A        return newSize;%0A    %7D
 %0A%7D%0A

Remove all the remaining code