001/** 002 * 003 * Copyright the original author or authors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 */ 017package org.jivesoftware.smack.util; 018 019 020/** 021 * A Base 64 encoding implementation that generates filename and Url safe encodings. 022 * 023 * <p> 024 * Note: This does NOT produce standard Base 64 encodings, but a variant as defined in 025 * Section 4 of RFC3548: 026 * <a href="http://www.faqs.org/rfcs/rfc3548.html">http://www.faqs.org/rfcs/rfc3548.html</a>. 027 * 028 * @author Robin Collier 029 */ 030public class Base64FileUrlEncoder implements StringEncoder { 031 032 private static Base64FileUrlEncoder instance = new Base64FileUrlEncoder(); 033 034 private Base64FileUrlEncoder() { 035 // Use getInstance() 036 } 037 038 public static Base64FileUrlEncoder getInstance() { 039 return instance; 040 } 041 042 public String encode(String s) { 043 return Base64.encodeBytes(s.getBytes(), Base64.URL_SAFE); 044 } 045 046 public String decode(String s) { 047 return new String(Base64.decode(s, Base64.URL_SAFE)); 048 } 049 050}