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);
}
本文介绍了一个使用Java实现的Base64编码转换器,该转换器包含两个主要功能:一是将Base64编码的字符串解析为字节数组;二是将字节数组格式化为Base64编码的字符串。此转换器通过实现Convertor接口,提供了通用的数据转换框架。
878

被折叠的 条评论
为什么被折叠?



