Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /** |
| 2 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | * you may not use this file except in compliance with the License. |
| 4 | * You may obtain a copy of the License at |
| 5 | * |
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | * |
| 8 | * Unless required by applicable law or agreed to in writing, software |
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | * See the License for the specific language governing permissions and |
| 12 | * limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package org.jivesoftware.smack.util; |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * A Base 64 encoding implementation that generates filename and Url safe encodings. |
| 20 | * |
| 21 | * <p> |
| 22 | * Note: This does NOT produce standard Base 64 encodings, but a variant as defined in |
| 23 | * Section 4 of RFC3548: |
| 24 | * <a href="http://www.faqs.org/rfcs/rfc3548.html">http://www.faqs.org/rfcs/rfc3548.html</a>. |
| 25 | * |
| 26 | * @author Robin Collier |
| 27 | */ |
| 28 | public class Base64FileUrlEncoder implements StringEncoder { |
| 29 | |
| 30 | private static Base64FileUrlEncoder instance = new Base64FileUrlEncoder(); |
| 31 | |
| 32 | private Base64FileUrlEncoder() { |
| 33 | // Use getInstance() |
| 34 | } |
| 35 | |
| 36 | public static Base64FileUrlEncoder getInstance() { |
| 37 | return instance; |
| 38 | } |
| 39 | |
| 40 | public String encode(String s) { |
| 41 | return Base64.encodeBytes(s.getBytes(), Base64.URL_SAFE); |
| 42 | } |
| 43 | |
| 44 | public String decode(String s) { |
| 45 | return new String(Base64.decode(s, Base64.URL_SAFE)); |
| 46 | } |
| 47 | |
| 48 | } |