001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.util.encoders;
019    
020    /**
021     * Convert binary data to and from UrlBase64 encoding.  This is identical to
022     * Base64 encoding, except that the padding character is "." and the other
023     * non-alphanumeric characters are "-" and "_" instead of "+" and "/".
024     * <p>
025     * The purpose of UrlBase64 encoding is to provide a compact encoding of binary
026     * data that is safe for use as an URL parameter. Base64 encoding does not
027     * produce encoded values that are safe for use in URLs, since "/" can be
028     * interpreted as a path delimiter; "+" is the encoded form of a space; and
029     * "=" is used to separate a name from the corresponding value in an URL
030     * parameter.
031     */
032    public class UrlBase64Encoder extends Base64Encoder
033    {
034        public UrlBase64Encoder()
035        {
036            encodingTable[encodingTable.length - 2] = (byte) '-';
037            encodingTable[encodingTable.length - 1] = (byte) '_';
038            padding = (byte) '.';
039            // we must re-create the decoding table with the new encoded values.
040            initialiseDecodingTable();
041        }
042    }