/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-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
*
*
* 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.
*
*/
/**
* Implementation of MIME's Base64 encoding and decoding conversions.
* Optimized code. (raw version taken from oreilly.jonathan.util,
* and currently com.sun.org.apache.xerces.internal.ds.util.Base64)
*
* @author Raul Benito(Of the xerces copy, and little adaptations).
* @author Anli Shundi
* @author Christian Geuer-Pollmann
* @see <A HREF="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</A>
* @see com.sun.org.apache.xml.internal.security.transforms.implementations.TransformBase64Decode
*/
public class Base64 {
/** Field BASE64DEFAULTLENGTH */
private Base64() {
// we don't allow instantiation
}
/**
* Returns a byte-array representation of a <code>{@link BigInteger}<code>.
* No sign-bit is outputed.
*
* <b>N.B.:</B> <code>{@link BigInteger}<code>'s toByteArray
* retunrs eventually longer arrays because of the leading sign-bit.
*
* @param big <code>BigInteger<code> to be converted
* @param bitlen <code>int<code> the desired length in bits of the representation
* @return a byte array with <code>bitlen</code> bits of <code>big</code>
*/
//round bitlen
throw new IllegalArgumentException(I18n
.translate("utils.Base64.IllegalBitlength"));
}
return bigBytes;
}
// some copying needed
bigLen--; // valid length of the string
}
return resizedBytes;
}
/**
* Encode in Base64 the given <code>{@link BigInteger}<code>.
*
* @param big
* @return String with Base64 encoding
*/
}
/**
* Returns a byte-array representation of a <code>{@link BigInteger}<code>.
* No sign-bit is outputed.
*
* <b>N.B.:</B> <code>{@link BigInteger}<code>'s toByteArray
* retunrs eventually longer arrays because of the leading sign-bit.
*
* @param big <code>BigInteger<code> to be converted
* @param bitlen <code>int<code> the desired length in bits of the representation
* @return a byte array with <code>bitlen</code> bits of <code>big</code>
*/
//round bitlen
throw new IllegalArgumentException(I18n
.translate("utils.Base64.IllegalBitlength"));
}
return bigBytes;
}
// some copying needed
bigLen--; // valid length of the string
}
return resizedBytes;
}
/**
* Method decodeBigIntegerFromElement
*
* @param element
* @return the biginter obtained from the node
* @throws Base64DecodingException
*/
public static final BigInteger decodeBigIntegerFromElement(Element element) throws Base64DecodingException
{
}
/**
* Method decodeBigIntegerFromText
*
* @param text
* @return the biginter obtained from the text node
* @throws Base64DecodingException
*/
{
}
/**
* This method takes an (empty) Element and a BigInteger and adds the
* base64 encoded BigInteger to the Element.
*
* @param element
* @param biginteger
*/
}
}
/**
* Method decode
*
* Takes the <CODE>Text</CODE> children of the Element and interprets
* them as input for the <CODE>Base64.decode()</CODE> function.
*
* @param element
* @return the byte obtained of the decoding the element
* $todo$ not tested yet
* @throws Base64DecodingException
*/
}
}
}
/**
* Method encodeToElement
*
* @param doc
* @param localName
* @param bytes
* @return an Element with the base64 encoded in the text.
*
*/
byte[] bytes) {
return el;
}
/**
* Method decode
*
*
* @param base64
* @return the UTF bytes of the base64
* @throws Base64DecodingException
*
*/
}
/**
* Encode a byte array and fold lines at the standard 76th character unless
* ignore line breaks property is set.
*
* @param binaryData <code>byte[]<code> to be base64 encoded
* @return the <code>String<code> with encoded data
*/
return XMLUtils.ignoreLineBreaks()
}
/**
* Base64 decode the lines from the reader and return an InputStream
* with the bytes.
*
*
* @param reader
* @return InputStream with the decoded bytes
* @exception IOException passes what the reader throws
* @throws IOException
* @throws Base64DecodingException
*/
throws IOException, Base64DecodingException {
}
return baos.toByteArray();
}
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--) {
}
for (int i = '9'; i >= '0'; i--) {
}
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);
}
}
}
/**
* Encodes hex octects into Base64
*
* @param binaryData Array containing binaryData
* @return Encoded Base64 array
*/
/**
* Encode a byte array in Base64 format and return an optionally
* wrapped line.
*
* @param binaryData <code>byte[]</code> data to be encoded
* @param length <code>int<code> length of wrapped lines; No wrapping if less than 4.
* @return a <code>String</code> with encoded data
*/
if (length<4) {
}
if (binaryData == null)
return null;
if (lengthDataBits == 0) {
return "";
}
char encodedData[] = null;
int encodedIndex = 0;
int dataIndex = 0;
int i = 0;
l = (byte)(b2 & 0x0f);
k = (byte)(b1 & 0x03);
i++;
}
}
for (; i<numberTriplets; i++) {
l = (byte)(b2 & 0x0f);
k = (byte)(b1 & 0x03);
}
// form integral number of 6-bit groups
if (fewerThan24bits == EIGHTBIT) {
k = (byte) ( b1 &0x03 );
} else if (fewerThan24bits == SIXTEENBIT) {
l = ( byte ) ( b2 &0x0f );
k = ( byte ) ( b1 &0x03 );
}
//encodedData[encodedIndex] = 0xa;
return new String(encodedData);
}
/**
* Decodes Base64 data into octects
*
* @param encoded String containing base64 encoded data
* @return byte array containing the decoded data
* @throws Base64DecodingException if there is a problem decoding the data
*/
return null;
}
int newSize=0;
for (int i = 0; i < length; i++) {
if (!isWhiteSpace(dataS))
}
return newSize;
}
protected final static byte[] decodeInternal(byte[] base64Data, int len) throws Base64DecodingException {
// remove white spaces
if (len==-1)
throw new Base64DecodingException("decoding.divisible.four");
//should be divisible by four
}
if (numberQuadruple == 0)
return new byte[0];
byte decodedData[] = null;
int i = 0;
int encodedIndex = 0;
int dataIndex = 0;
//decodedData = new byte[ (numberQuadruple)*3];
//first last bits.
}
//Check if they are PAD characters
throw new Base64DecodingException("decoding.general");
throw new Base64DecodingException("decoding.general");
} else {
throw new Base64DecodingException("decoding.general");//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
}
} else {
//No PAD e.g 3cQl
}
encodedIndex=0;
dataIndex=0;
//the begin
if ( (b1==-1) ||
(b2==-1) ||
(b3==-1) ||
(b4==-1) ) {
}
}
return decodedData;
}
/**
* Decodes Base64 data into outputstream
*
* @param base64Data String containing Base64 data
* @param os the outputstream
* @throws IOException
* @throws Base64DecodingException
*/
}
/**
* Decodes Base64 data into outputstream
*
* @param base64Data Byte array containing Base64 data
* @param os the outputstream
* @throws IOException
* @throws Base64DecodingException
*/
}
// remove white spaces
if (len==-1)
throw new Base64DecodingException("decoding.divisible.four");
//should be divisible by four
}
if (numberQuadruple == 0)
return;
//byte decodedData[] = null;
int i = 0;
int dataIndex = 0;
//the begin
if ( (b1==-1) ||
(b2==-1) ||
(b3==-1) ||
(b4==-1) )
}
// first last bits.
if ((b1==-1) ||
(b2==-1) ){
}
if ((b3==-1 ) ||
throw new Base64DecodingException("decoding.general");
throw new Base64DecodingException("decoding.general");
} else {
throw new Base64DecodingException("decoding.general");//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
}
} else {
//No PAD e.g 3cQl
}
return ;
}
/**
* Decodes Base64 data into outputstream
*
* @param is containing Base64 data
* @param os the outputstream
* @throws IOException
* @throws Base64DecodingException
*/
//byte decodedData[] = null;
int index=0;
byte []data=new byte[4];
int read;
//the begin
if (isWhiteSpace(readed)) {
continue;
}
if (index==3)
break;
}
}
if (index!=4) {
continue;
}
index=0;
}
if ((b3==-1 ) ||
throw new Base64DecodingException("decoding.general");
throw new Base64DecodingException("decoding.general");
} else {
throw new Base64DecodingException("decoding.general");//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
}
} else {
//No PAD e.g 3cQl
}
return ;
}
/**
* remove WhiteSpace from MIME containing encoded Base64 data.
*
* @param data the byte array of base64 data (with WS)
* @return the new length
*/
return 0;
// count characters that's not whitespace
int newSize = 0;
for (int i = 0; i < len; i++) {
if (!isWhiteSpace(dataS))
}
return newSize;
}
}