<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FDevelopment%2FBase64</id>
		<title>Java Tutorial/Development/Base64 - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FDevelopment%2FBase64"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Development/Base64&amp;action=history"/>
		<updated>2026-04-23T10:11:43Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Development/Base64&amp;diff=3654&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Development/Base64&amp;diff=3654&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Development/Base64&amp;diff=3655&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Development/Base64&amp;diff=3655&amp;oldid=prev"/>
				<updated>2010-05-31T15:28:29Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Base64 encoding/decoding. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * The contents of this file are subject to the terms of either the GNU&lt;br /&gt;
 * General Public License Version 2 only (&amp;quot;GPL&amp;quot;) or the Common&lt;br /&gt;
 * Development and Distribution License(&amp;quot;CDDL&amp;quot;) (collectively, the&lt;br /&gt;
 * &amp;quot;License&amp;quot;). You may not use this file except in compliance with the&lt;br /&gt;
 * License. You can obtain a copy of the License at&lt;br /&gt;
 * http://www.netbeans.org/cddl-gplv2.html&lt;br /&gt;
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the&lt;br /&gt;
 * specific language governing permissions and limitations under the&lt;br /&gt;
 * License.  When distributing the software, include this License Header&lt;br /&gt;
 * Notice in each file and include the License file at&lt;br /&gt;
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this&lt;br /&gt;
 * particular file as subject to the &amp;quot;Classpath&amp;quot; exception as provided&lt;br /&gt;
 * by Sun in the GPL Version 2 section of the License file that&lt;br /&gt;
 * accompanied this code. If applicable, add the following below the&lt;br /&gt;
 * License Header, with the fields enclosed by brackets [] replaced by&lt;br /&gt;
 * your own identifying information:&lt;br /&gt;
 * &amp;quot;Portions Copyrighted [year] [name of copyright owner]&amp;quot;&lt;br /&gt;
 *&lt;br /&gt;
 * Contributor(s):&lt;br /&gt;
 *&lt;br /&gt;
 * The Original Software is NetBeans. The Initial Developer of the Original&lt;br /&gt;
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun&lt;br /&gt;
 * Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * If you wish your version of this file to be governed by only the CDDL&lt;br /&gt;
 * or only the GPL Version 2, indicate your decision by adding&lt;br /&gt;
 * &amp;quot;[Contributor] elects to include this software in this distribution&lt;br /&gt;
 * under the [CDDL or GPL Version 2] license.&amp;quot; If you do not indicate a&lt;br /&gt;
 * single choice of license, a recipient has the option to distribute&lt;br /&gt;
 * your version of this file under either the CDDL, the GPL Version 2 or&lt;br /&gt;
 * to extend the choice of license to its licensees as provided above.&lt;br /&gt;
 * However, if you add GPL Version 2 code and therefore, elected the GPL&lt;br /&gt;
 * Version 2 license, then the option applies only if the new code is&lt;br /&gt;
 * made subject to such option by the copyright holder.&lt;br /&gt;
 */&lt;br /&gt;
/** This class provides Base64 encoding/decoding.&lt;br /&gt;
 */&lt;br /&gt;
public class Base64&lt;br /&gt;
{&lt;br /&gt;
    private Base64()&lt;br /&gt;
    {&lt;br /&gt;
        //Avoid instantiation of this class&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /** Encodes datas using base64 encoding.&lt;br /&gt;
     * @param abyte0 data for encoding&lt;br /&gt;
     * @return encoded string&lt;br /&gt;
     */&lt;br /&gt;
    static String encode(final byte abyte0[])&lt;br /&gt;
    {&lt;br /&gt;
        final StringBuffer stringbuffer = new StringBuffer();&lt;br /&gt;
        for(int i = 0; i &amp;lt; abyte0.length; i += 3)&lt;br /&gt;
            stringbuffer.append(encodeBlock(abyte0, i));&lt;br /&gt;
        &lt;br /&gt;
        return stringbuffer.toString();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private static char[] encodeBlock(final byte abyte0[], final int i)&lt;br /&gt;
    {&lt;br /&gt;
        int j = 0;&lt;br /&gt;
        final int k = abyte0.length - i - 1;&lt;br /&gt;
        final int l = k &amp;lt; 2 ? k : 2;&lt;br /&gt;
        for(int i1 = 0; i1 &amp;lt;= l; i1++)&lt;br /&gt;
        {&lt;br /&gt;
            final byte byte0 = abyte0[i + i1];&lt;br /&gt;
            final int j1 = byte0 &amp;gt;= 0 ? ((int) (byte0)) : byte0 + 256;&lt;br /&gt;
            j += j1 &amp;lt;&amp;lt; 8 * (2 - i1);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        char ac[] = new char[4];&lt;br /&gt;
        for(int k1 = 0; k1 &amp;lt; 4; k1++)&lt;br /&gt;
        {&lt;br /&gt;
            final int l1 = j &amp;gt;&amp;gt;&amp;gt; 6 * (3 - k1) &amp;amp; 0x3f;&lt;br /&gt;
            ac[k1] = getChar(l1);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        if(k &amp;lt; 1)&lt;br /&gt;
            ac[2] = &amp;quot;=&amp;quot;;&lt;br /&gt;
        if(k &amp;lt; 2)&lt;br /&gt;
            ac[3] = &amp;quot;=&amp;quot;;&lt;br /&gt;
        return ac;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private static char getChar(final int i)&lt;br /&gt;
    {&lt;br /&gt;
        if(i &amp;gt;= 0 &amp;amp;&amp;amp; i &amp;lt;= 25)&lt;br /&gt;
            return (char)(65 + i);&lt;br /&gt;
        if(i &amp;gt;= 26 &amp;amp;&amp;amp; i &amp;lt;= 51)&lt;br /&gt;
            return (char)(97 + (i - 26));&lt;br /&gt;
        if(i &amp;gt;= 52 &amp;amp;&amp;amp; i &amp;lt;= 61)&lt;br /&gt;
            return (char)(48 + (i - 52));&lt;br /&gt;
        if(i == 62)&lt;br /&gt;
            return &amp;quot;+&amp;quot;;&lt;br /&gt;
        return i != 63 ? &amp;quot;?&amp;quot; : &amp;quot;/&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /** Decode string using Base64 encoding.&lt;br /&gt;
     * @param s string for decoding&lt;br /&gt;
     * @return decoded data&lt;br /&gt;
     */&lt;br /&gt;
    static byte[] decode(final String s)&lt;br /&gt;
    {&lt;br /&gt;
        if (s.length() == 0) return new byte[0];&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        for(int j = s.length() - 1; j &amp;gt; 0 &amp;amp;&amp;amp; s.charAt(j) == &amp;quot;=&amp;quot;; j--)&lt;br /&gt;
            i++;&lt;br /&gt;
        &lt;br /&gt;
        final int k = (s.length() * 6) / 8 - i;&lt;br /&gt;
        byte abyte0[] = new byte[k];&lt;br /&gt;
        int l = 0;&lt;br /&gt;
        for(int i1 = 0; i1 &amp;lt; s.length(); i1 += 4)&lt;br /&gt;
        {&lt;br /&gt;
            final int j1 = (getValue(s.charAt(i1)) &amp;lt;&amp;lt; 18) + (getValue(s.charAt(i1 + 1)) &amp;lt;&amp;lt; 12) + (getValue(s.charAt(i1 + 2)) &amp;lt;&amp;lt; 6) + getValue(s.charAt(i1 + 3));&lt;br /&gt;
            for(int k1 = 0; k1 &amp;lt; 3 &amp;amp;&amp;amp; l + k1 &amp;lt; abyte0.length; k1++)&lt;br /&gt;
                abyte0[l + k1] = (byte)(j1 &amp;gt;&amp;gt; 8 * (2 - k1) &amp;amp; 0xff);&lt;br /&gt;
            &lt;br /&gt;
            l += 3;&lt;br /&gt;
        }&lt;br /&gt;
        return abyte0;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private static int getValue(final char c)&lt;br /&gt;
    {&lt;br /&gt;
        if(c &amp;gt;= &amp;quot;A&amp;quot; &amp;amp;&amp;amp; c &amp;lt;= &amp;quot;Z&amp;quot;)&lt;br /&gt;
            return c - 65;&lt;br /&gt;
        if(c &amp;gt;= &amp;quot;a&amp;quot; &amp;amp;&amp;amp; c &amp;lt;= &amp;quot;z&amp;quot;)&lt;br /&gt;
            return (c - 97) + 26;&lt;br /&gt;
        if(c &amp;gt;= &amp;quot;0&amp;quot; &amp;amp;&amp;amp; c &amp;lt;= &amp;quot;9&amp;quot;)&lt;br /&gt;
            return (c - 48) + 52;&lt;br /&gt;
        if(c == &amp;quot;+&amp;quot;)&lt;br /&gt;
            return 62;&lt;br /&gt;
        if(c == &amp;quot;/&amp;quot;)&lt;br /&gt;
            return 63;&lt;br /&gt;
        return c != &amp;quot;=&amp;quot; ? -1 : 0;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Encode/decode for RFC ase64 as defined by RFC 2045 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one or more&lt;br /&gt;
 * contributor license agreements.  See the NOTICE file distributed with&lt;br /&gt;
 * this work for additional information regarding copyright ownership.&lt;br /&gt;
 * The ASF licenses this file to You under the Apache License, Version 2.0&lt;br /&gt;
 * (the &amp;quot;License&amp;quot;); you may not use this file except in compliance with&lt;br /&gt;
 * the License.  You may obtain a copy of the License at&lt;br /&gt;
 * &lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 * &lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * This class provides encode/decode for RFC 2045 Base64 as defined by&lt;br /&gt;
 * RFC 2045, N. Freed and N. Borenstein.  :&lt;br /&gt;
 * Multipurpose Internet Mail Extensions (MIME) Part One: Format of&lt;br /&gt;
 * Internet Message Bodies. Reference 1996&lt;br /&gt;
 *&lt;br /&gt;
 * @author Jeffrey Rodriguez&lt;br /&gt;
 * @version $Id: Base64.java 515 2008-03-17 21:02:23Z jfrederic.clere@jboss.ru $&lt;br /&gt;
 */&lt;br /&gt;
public final class  Base64&lt;br /&gt;
{&lt;br /&gt;
    static private final int  BASELENGTH         = 255;&lt;br /&gt;
    static private final int  LOOKUPLENGTH       = 64;&lt;br /&gt;
    static private final int  TWENTYFOURBITGROUP = 24;&lt;br /&gt;
    static private final int  EIGHTBIT           = 8;&lt;br /&gt;
    static private final int  SIXTEENBIT         = 16;&lt;br /&gt;
    static private final int  SIXBIT             = 6;&lt;br /&gt;
    static private final int  FOURBYTE           = 4;&lt;br /&gt;
    static private final int  SIGN               = -128;&lt;br /&gt;
    static private final byte PAD                = (byte) &amp;quot;=&amp;quot;;&lt;br /&gt;
    static private byte [] base64Alphabet       = new byte[BASELENGTH];&lt;br /&gt;
    static private byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];&lt;br /&gt;
    //static private final Log log = LogSource.getInstance(&amp;quot;org.apache.rumons.util.Base64&amp;quot;);&lt;br /&gt;
    static&lt;br /&gt;
    {&lt;br /&gt;
        for (int i = 0; i &amp;lt; BASELENGTH; i++ )&lt;br /&gt;
        {&lt;br /&gt;
            base64Alphabet[i] = -1;&lt;br /&gt;
        }&lt;br /&gt;
        for (int i = &amp;quot;Z&amp;quot;; i &amp;gt;= &amp;quot;A&amp;quot;; i--)&lt;br /&gt;
        {&lt;br /&gt;
            base64Alphabet[i] = (byte) (i - &amp;quot;A&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        for (int i = &amp;quot;z&amp;quot;; i&amp;gt;= &amp;quot;a&amp;quot;; i--)&lt;br /&gt;
        {&lt;br /&gt;
            base64Alphabet[i] = (byte) (i - &amp;quot;a&amp;quot; + 26);&lt;br /&gt;
        }&lt;br /&gt;
        for (int i = &amp;quot;9&amp;quot;; i &amp;gt;= &amp;quot;0&amp;quot;; i--)&lt;br /&gt;
        {&lt;br /&gt;
            base64Alphabet[i] = (byte) (i - &amp;quot;0&amp;quot; + 52);&lt;br /&gt;
        }&lt;br /&gt;
        base64Alphabet[&amp;quot;+&amp;quot;]  = 62;&lt;br /&gt;
        base64Alphabet[&amp;quot;/&amp;quot;]  = 63;&lt;br /&gt;
        for (int i = 0; i &amp;lt;= 25; i++ )&lt;br /&gt;
            lookUpBase64Alphabet[i] = (byte) (&amp;quot;A&amp;quot; + i);&lt;br /&gt;
        for (int i = 26,  j = 0; i &amp;lt;= 51; i++, j++ )&lt;br /&gt;
            lookUpBase64Alphabet[i] = (byte) (&amp;quot;a&amp;quot;+ j);&lt;br /&gt;
        for (int i = 52,  j = 0; i &amp;lt;= 61; i++, j++ )&lt;br /&gt;
            lookUpBase64Alphabet[i] = (byte) (&amp;quot;0&amp;quot; + j);&lt;br /&gt;
        lookUpBase64Alphabet[62] = (byte) &amp;quot;+&amp;quot;;&lt;br /&gt;
        lookUpBase64Alphabet[63] = (byte) &amp;quot;/&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    public static boolean isBase64( String isValidString )&lt;br /&gt;
    {&lt;br /&gt;
        return isArrayByteBase64(isValidString.getBytes());&lt;br /&gt;
    }&lt;br /&gt;
    public static boolean isBase64( byte octect )&lt;br /&gt;
    {&lt;br /&gt;
        //shall we ignore white space? JEFF??&lt;br /&gt;
        return (octect == PAD || base64Alphabet[octect] != -1);&lt;br /&gt;
    }&lt;br /&gt;
    public static boolean isArrayByteBase64( byte[] arrayOctect )&lt;br /&gt;
    {&lt;br /&gt;
        int length = arrayOctect.length;&lt;br /&gt;
        if (length == 0)&lt;br /&gt;
        {&lt;br /&gt;
            // shouldn&amp;quot;t a 0 length array be valid base64 data?&lt;br /&gt;
            // return false;&lt;br /&gt;
            return true;&lt;br /&gt;
        }&lt;br /&gt;
        for (int i=0; i &amp;lt; length; i++)&lt;br /&gt;
        {&lt;br /&gt;
            if ( !Base64.isBase64(arrayOctect[i]) )&lt;br /&gt;
                return false;&lt;br /&gt;
        }&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Encodes hex octects into Base64.&lt;br /&gt;
     *&lt;br /&gt;
     * @param binaryData Array containing binary data to encode.&lt;br /&gt;
     * @return Base64-encoded data.&lt;br /&gt;
     */&lt;br /&gt;
    public static byte[] encode( byte[] binaryData )&lt;br /&gt;
    {&lt;br /&gt;
        int      lengthDataBits    = binaryData.length*EIGHTBIT;&lt;br /&gt;
        int      fewerThan24bits   = lengthDataBits%TWENTYFOURBITGROUP;&lt;br /&gt;
        int      numberTriplets    = lengthDataBits/TWENTYFOURBITGROUP;&lt;br /&gt;
        byte     encodedData[]     = null;&lt;br /&gt;
&lt;br /&gt;
        if (fewerThan24bits != 0)&lt;br /&gt;
        {&lt;br /&gt;
            //data not divisible by 24 bit&lt;br /&gt;
            encodedData = new byte[ (numberTriplets + 1 ) * 4 ];&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            // 16 or 8 bit&lt;br /&gt;
            encodedData = new byte[ numberTriplets * 4 ];&lt;br /&gt;
        }&lt;br /&gt;
        byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;&lt;br /&gt;
        int encodedIndex = 0;&lt;br /&gt;
        int dataIndex   = 0;&lt;br /&gt;
        int i           = 0;&lt;br /&gt;
        //log.debug(&amp;quot;number of triplets = &amp;quot; + numberTriplets);&lt;br /&gt;
        for ( i = 0; i&amp;lt;numberTriplets; i++ )&lt;br /&gt;
        {&lt;br /&gt;
            dataIndex = i*3;&lt;br /&gt;
            b1 = binaryData[dataIndex];&lt;br /&gt;
            b2 = binaryData[dataIndex + 1];&lt;br /&gt;
            b3 = binaryData[dataIndex + 2];&lt;br /&gt;
            //log.debug(&amp;quot;b1= &amp;quot; + b1 +&amp;quot;, b2= &amp;quot; + b2 + &amp;quot;, b3= &amp;quot; + b3);&lt;br /&gt;
            l  = (byte)(b2 &amp;amp; 0x0f);&lt;br /&gt;
            k  = (byte)(b1 &amp;amp; 0x03);&lt;br /&gt;
            encodedIndex = i * 4;&lt;br /&gt;
            byte val1 = ((b1 &amp;amp; SIGN)==0)?(byte)(b1&amp;gt;&amp;gt;2):(byte)((b1)&amp;gt;&amp;gt;2^0xc0);&lt;br /&gt;
            byte val2 = ((b2 &amp;amp; SIGN)==0)?(byte)(b2&amp;gt;&amp;gt;4):(byte)((b2)&amp;gt;&amp;gt;4^0xf0);&lt;br /&gt;
            byte val3 = ((b3 &amp;amp; SIGN)==0)?(byte)(b3&amp;gt;&amp;gt;6):(byte)((b3)&amp;gt;&amp;gt;6^0xfc);&lt;br /&gt;
            encodedData[encodedIndex]   = lookUpBase64Alphabet[ val1 ];&lt;br /&gt;
            //log.debug( &amp;quot;val2 = &amp;quot; + val2 );&lt;br /&gt;
            //log.debug( &amp;quot;k4   = &amp;quot; + (k&amp;lt;&amp;lt;4) );&lt;br /&gt;
            //log.debug(  &amp;quot;vak  = &amp;quot; + (val2 | (k&amp;lt;&amp;lt;4)) );&lt;br /&gt;
            encodedData[encodedIndex+1] =&lt;br /&gt;
                lookUpBase64Alphabet[ val2 | ( k&amp;lt;&amp;lt;4 )];&lt;br /&gt;
            encodedData[encodedIndex+2] =&lt;br /&gt;
                lookUpBase64Alphabet[ (l &amp;lt;&amp;lt;2 ) | val3 ];&lt;br /&gt;
            encodedData[encodedIndex+3] = lookUpBase64Alphabet[ b3 &amp;amp; 0x3f ];&lt;br /&gt;
        }&lt;br /&gt;
        // form integral number of 6-bit groups&lt;br /&gt;
        dataIndex    = i*3;&lt;br /&gt;
        encodedIndex = i*4;&lt;br /&gt;
        if (fewerThan24bits == EIGHTBIT )&lt;br /&gt;
        {&lt;br /&gt;
            b1 = binaryData[dataIndex];&lt;br /&gt;
            k = (byte) ( b1 &amp;amp;0x03 );&lt;br /&gt;
            //log.debug(&amp;quot;b1=&amp;quot; + b1);&lt;br /&gt;
            //log.debug(&amp;quot;b1&amp;lt;&amp;lt;2 = &amp;quot; + (b1&amp;gt;&amp;gt;2) );&lt;br /&gt;
            byte val1 = ((b1 &amp;amp; SIGN)==0)?(byte)(b1&amp;gt;&amp;gt;2):(byte)((b1)&amp;gt;&amp;gt;2^0xc0);&lt;br /&gt;
            encodedData[encodedIndex]     = lookUpBase64Alphabet[ val1 ];&lt;br /&gt;
            encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ k&amp;lt;&amp;lt;4 ];&lt;br /&gt;
            encodedData[encodedIndex + 2] = PAD;&lt;br /&gt;
            encodedData[encodedIndex + 3] = PAD;&lt;br /&gt;
        }&lt;br /&gt;
        else if (fewerThan24bits == SIXTEENBIT)&lt;br /&gt;
        {&lt;br /&gt;
            b1 = binaryData[dataIndex];&lt;br /&gt;
            b2 = binaryData[dataIndex +1 ];&lt;br /&gt;
            l = (byte) (b2 &amp;amp; 0x0f);&lt;br /&gt;
            k = (byte) (b1 &amp;amp; 0x03);&lt;br /&gt;
            byte val1 = ((b1 &amp;amp; SIGN) == 0)?(byte)(b1&amp;gt;&amp;gt;2):(byte)((b1)&amp;gt;&amp;gt;2^0xc0);&lt;br /&gt;
            byte val2 = ((b2 &amp;amp; SIGN) == 0)?(byte)(b2&amp;gt;&amp;gt;4):(byte)((b2)&amp;gt;&amp;gt;4^0xf0);&lt;br /&gt;
            encodedData[encodedIndex]     = lookUpBase64Alphabet[ val1 ];&lt;br /&gt;
            encodedData[encodedIndex + 1] =&lt;br /&gt;
                lookUpBase64Alphabet[ val2 | ( k&amp;lt;&amp;lt;4 )];&lt;br /&gt;
            encodedData[encodedIndex + 2] = lookUpBase64Alphabet[ l&amp;lt;&amp;lt;2 ];&lt;br /&gt;
            encodedData[encodedIndex + 3] = PAD;&lt;br /&gt;
        }&lt;br /&gt;
        return encodedData;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  to Base64 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/****************************************************************&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one   *&lt;br /&gt;
 * or more contributor license agreements.  See the NOTICE file *&lt;br /&gt;
 * distributed with this work for additional information        *&lt;br /&gt;
 * regarding copyright ownership.  The ASF licenses this file   *&lt;br /&gt;
 * to you under the Apache License, Version 2.0 (the            *&lt;br /&gt;
 * &amp;quot;License&amp;quot;); you may not use this file except in compliance   *&lt;br /&gt;
 * with the License.  You may obtain a copy of the License at   *&lt;br /&gt;
 *                                                              *&lt;br /&gt;
 *   http://www.apache.org/licenses/LICENSE-2.0                 *&lt;br /&gt;
 *                                                              *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing,   *&lt;br /&gt;
 * software distributed under the License is distributed on an  *&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *&lt;br /&gt;
 * KIND, either express or implied.  See the License for the    *&lt;br /&gt;
 * specific language governing permissions and limitations      *&lt;br /&gt;
 * under the License.                                           *&lt;br /&gt;
 ****************************************************************/&lt;br /&gt;
&lt;br /&gt;
public class EncodeUtils {&lt;br /&gt;
    &lt;br /&gt;
    public static final int MASK = 0x3F;&lt;br /&gt;
    public static final int FIRST_MASK = MASK &amp;lt;&amp;lt; 18; &lt;br /&gt;
    public static final int SECOND_MASK = MASK &amp;lt;&amp;lt; 12; &lt;br /&gt;
    public static final int THIRD_MASK = MASK &amp;lt;&amp;lt; 6; &lt;br /&gt;
    public static final int FORTH_MASK = MASK; &lt;br /&gt;
    &lt;br /&gt;
    public static final byte[] ENCODING = {&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;, &amp;quot;E&amp;quot;, &amp;quot;F&amp;quot;, &amp;quot;G&amp;quot;, &amp;quot;H&amp;quot;, &amp;quot;I&amp;quot;, &amp;quot;J&amp;quot;, &amp;quot;K&amp;quot;, &amp;quot;L&amp;quot;, &amp;quot;M&amp;quot;, &amp;quot;N&amp;quot;,&lt;br /&gt;
        &amp;quot;O&amp;quot;, &amp;quot;P&amp;quot; ,&amp;quot;Q&amp;quot;, &amp;quot;R&amp;quot;, &amp;quot;S&amp;quot;, &amp;quot;T&amp;quot;, &amp;quot;U&amp;quot;, &amp;quot;V&amp;quot;, &amp;quot;W&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;Y&amp;quot;, &amp;quot;Z&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;d&amp;quot;, &amp;quot;e&amp;quot;, &amp;quot;f&amp;quot;, &amp;quot;g&amp;quot;, &amp;quot;h&amp;quot;, &amp;quot;i&amp;quot;,&lt;br /&gt;
        &amp;quot;j&amp;quot;, &amp;quot;k&amp;quot;, &amp;quot;l&amp;quot;, &amp;quot;m&amp;quot;, &amp;quot;n&amp;quot;, &amp;quot;o&amp;quot;, &amp;quot;p&amp;quot;, &amp;quot;q&amp;quot;, &amp;quot;r&amp;quot;, &amp;quot;s&amp;quot;, &amp;quot;t&amp;quot;, &amp;quot;u&amp;quot;, &amp;quot;v&amp;quot;, &amp;quot;w&amp;quot;, &amp;quot;x&amp;quot;, &amp;quot;y&amp;quot;, &amp;quot;z&amp;quot;, &amp;quot;0&amp;quot;, &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;, &amp;quot;3&amp;quot;,&lt;br /&gt;
        &amp;quot;4&amp;quot;, &amp;quot;5&amp;quot;, &amp;quot;6&amp;quot;, &amp;quot;7&amp;quot;, &amp;quot;8&amp;quot;, &amp;quot;9&amp;quot;, &amp;quot;+&amp;quot;, &amp;quot;/&amp;quot;};&lt;br /&gt;
    &lt;br /&gt;
    public static final void main(String[] args) throws Exception {&lt;br /&gt;
        byte[] bytes = {(byte) 0, (byte) 128, (byte) 0};&lt;br /&gt;
        System.out.println(new String(toBase64(bytes)));&lt;br /&gt;
        System.out.println(new String(toBase64(&amp;quot;Hello, World&amp;quot;.getBytes())));&lt;br /&gt;
        System.out.println(new String(toBase64(&amp;quot;Monday&amp;quot;.getBytes())));&lt;br /&gt;
        System.out.println(new String(toBase64(&amp;quot;M\u00F6nchengladbach\r\n&amp;quot;.getBytes(&amp;quot;ISO-8859-1&amp;quot;))));&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static byte[] toBase64(byte[] in) {&lt;br /&gt;
        int inputLength = in.length;&lt;br /&gt;
        int outputLength = (int) Math.floor((4*inputLength) / 3f) + 3;&lt;br /&gt;
        outputLength = outputLength + 2 * (int) Math.floor(outputLength / 76f);&lt;br /&gt;
        byte[] results = new byte[outputLength];&lt;br /&gt;
        int inputIndex = 0;&lt;br /&gt;
        int outputIndex = 0;&lt;br /&gt;
        while (inputLength - inputIndex &amp;gt; 2) {&lt;br /&gt;
            int one = (toInt(in[inputIndex++]) &amp;lt;&amp;lt; 16);&lt;br /&gt;
            int two = (toInt(in[inputIndex++]) &amp;lt;&amp;lt; 8);&lt;br /&gt;
            int three = toInt(in[inputIndex++]);&lt;br /&gt;
            int quantum = one | two | three;&lt;br /&gt;
            int index = (quantum &amp;amp; FIRST_MASK) &amp;gt;&amp;gt; 18;&lt;br /&gt;
            outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
            index = (quantum &amp;amp; SECOND_MASK) &amp;gt;&amp;gt; 12;&lt;br /&gt;
            outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
            index = (quantum &amp;amp; THIRD_MASK) &amp;gt;&amp;gt; 6;&lt;br /&gt;
            outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
            index = (quantum &amp;amp; FORTH_MASK);&lt;br /&gt;
            outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        switch (inputLength - inputIndex) {&lt;br /&gt;
            case 1:&lt;br /&gt;
                int quantum = in[inputIndex++] &amp;lt;&amp;lt; 16;&lt;br /&gt;
                int index = (quantum &amp;amp; FIRST_MASK) &amp;gt;&amp;gt; 18;&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
                index = (quantum &amp;amp; SECOND_MASK) &amp;gt;&amp;gt; 12;&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, (byte) &amp;quot;=&amp;quot;);&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, (byte) &amp;quot;=&amp;quot;);&lt;br /&gt;
                break;&lt;br /&gt;
                &lt;br /&gt;
            case 2:&lt;br /&gt;
                quantum = (in[inputIndex++] &amp;lt;&amp;lt; 16) + (in[inputIndex++] &amp;lt;&amp;lt; 8);&lt;br /&gt;
                index = (quantum &amp;amp; FIRST_MASK) &amp;gt;&amp;gt; 18;&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
                index = (quantum &amp;amp; SECOND_MASK) &amp;gt;&amp;gt; 12;&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
                index = (quantum &amp;amp; THIRD_MASK) &amp;gt;&amp;gt; 6;&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, ENCODING[index]);&lt;br /&gt;
                outputIndex = setResult(results, outputIndex, (byte) &amp;quot;=&amp;quot;);&lt;br /&gt;
                break;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return results;&lt;br /&gt;
    }&lt;br /&gt;
    private static int toInt(byte b) {&lt;br /&gt;
        return 255 &amp;amp; b;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static int setResult(byte[] results, int outputIndex, byte value) {&lt;br /&gt;
        results[outputIndex++] = value;&lt;br /&gt;
        outputIndex = checkLineLength(results, outputIndex);&lt;br /&gt;
        return outputIndex;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    private static int checkLineLength(byte[] results, int outputIndex) {&lt;br /&gt;
        if (outputIndex == 76 || outputIndex &amp;gt; 76 &amp;amp;&amp;amp; (outputIndex - 2*Math.floor(outputIndex/76f - 1)) % 76 == 0) {&lt;br /&gt;
            results[outputIndex++] = &amp;quot;\r&amp;quot;;&lt;br /&gt;
            results[outputIndex++] = &amp;quot;\n&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
        return outputIndex;&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>