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.stringencoder.java7; 018 019import java.util.Base64; 020 021/** 022 * A Base 64 encoding implementation. 023 * @author Florian Schmaus 024 */ 025public final class Java7Base64Encoder implements org.jivesoftware.smack.util.stringencoder.Base64.Encoder { 026 027 private static final Java7Base64Encoder instance = new Java7Base64Encoder(); 028 029 private final Base64.Encoder encoder; 030 private final Base64.Encoder encoderWithoutPadding; 031 032 private final Base64.Decoder decoder; 033 034 private Java7Base64Encoder() { 035 encoder = Base64.getEncoder(); 036 encoderWithoutPadding = encoder.withoutPadding(); 037 decoder = Base64.getDecoder(); 038 } 039 040 public static Java7Base64Encoder getInstance() { 041 return instance; 042 } 043 044 @Override 045 public byte[] decode(String string) { 046 return decoder.decode(string); 047 } 048 049 @Override 050 public String encodeToString(byte[] input) { 051 return encoder.encodeToString(input); 052 } 053 054 @Override 055 public String encodeToStringWithoutPadding(byte[] input) { 056 return encoderWithoutPadding.encodeToString(input); 057 } 058 059 @Override 060 public byte[] encode(byte[] input) { 061 return encoder.encode(input); 062 } 063}