BASE64Decoder.java revision 0
4632N/A * Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved. 4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4632N/A * This code is free software; you can redistribute it and/or modify it 4632N/A * under the terms of the GNU General Public License version 2 only, as 4632N/A * published by the Free Software Foundation. Sun designates this 4632N/A * particular file as subject to the "Classpath" exception as provided 4632N/A * by Sun in the LICENSE file that accompanied this code. 4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4632N/A * version 2 for more details (a copy is included in the LICENSE file that 4632N/A * You should have received a copy of the GNU General Public License version 4632N/A * 2 along with this work; if not, write to the Free Software Foundation, 4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4632N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4632N/A * CA 95054 USA or visit www.sun.com if you need additional information or 4632N/A * This class implements a BASE64 Character decoder as specified in RFC1521. 4632N/A * This RFC is part of the MIME specification which is published by the 4632N/A * Internet Engineering Task Force (IETF). Unlike some other encoding 4632N/A * schemes there is nothing in this encoding that tells the decoder 4632N/A * where a buffer starts or stops, so to use it you will need to isolate 4632N/A * your encoded data into a single chunk and then feed them this decoder. 4632N/A * The simplest way to do that is to read all of the encoded data into a 4632N/A * BASE64Decoder base64 = new BASE64Decoder(); 4632N/A * mydata = base64.decodeBuffer(bufferString); 4632N/A * This will decode the String in <i>bufferString</i> and give you an array 4632N/A * of bytes in the array <i>myData</i>. 4632N/A * On errors, this class throws a CEFormatException with the following detail 4632N/A * "BASE64Decoder: Not enough bytes for an atom." 4632N/A /** This class has 4 bytes per atom */ 4632N/A /** Any multiple of 4 will do, 72 might be common */ 4632N/A * This character array provides the character to value map 4632N/A 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
// 0 4632N/A 'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
// 1 4632N/A 'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
// 2 4632N/A 'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
// 3 4632N/A 'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
// 4 4632N/A 'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
// 5 4632N/A 'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
// 6 4632N/A '4',
'5',
'6',
'7',
'8',
'9',
'+',
'/' // 7 4632N/A for (
int i =
0; i <
255; i++) {
4632N/A * Decode one BASE64 atom into 1, 2, or 3 bytes of data. byte a = -
1, b = -
1, c = -
1, d = -
1;
}
while (i ==
'\n' || i ==
'\r');