import java.io.IOException; import net.iharder.Base64; public class Base64Convertor implements Convertor<byte[]>{ @Override public byte[] parse(String strValue){ try{ return Base64.decode(strValue); }catch (IOException e){ e.printStackTrace(); throw new RuntimeException("Decode with Base64 error."); } } @Override public String format(byte[] value){ return Base64.encodeBytes(value); } }
public interface Convertor<T> { T parse(String strValue); String format(T value); }