publicstaticFilebase64ToFile(Stringbase64) throwsBase64DecodingException {
if(base64==null||"".equals(base64)) {
returnnull;
}
byte[] buff=Base64.decode(base64);
Filefile=null;
FileOutputStreamfout=null;
try {
file=File.createTempFile("tmp", null);
fout=newFileOutputStream(file);
fout.write(buff);
} catch (IOExceptione) {
e.printStackTrace();
}finally {
if(fout!=null) {
try {
fout.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
}
returnfile;
}
publicstaticStringfile2Base64(Filefile) {
if(file==null) {
returnnull;
}
Stringbase64=null;
FileInputStreamfin=null;
try {
fin=newFileInputStream(file);
byte[] buff=newbyte[fin.available()];
fin.read(buff);
base64=Base64.encode(buff);
} catch (FileNotFoundExceptione) {
e.printStackTrace();
} catch (IOExceptione) {
e.printStackTrace();
} finally {
if (fin!=null) {
try {
fin.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
}
returnbase64;
}
publicstaticInputStreamBaseToInputStream(Stringbase64string) {
ByteArrayInputStreamstream=null;
try {
BASE64Decoderdecoder=newBASE64Decoder();
byte[] bytes1=decoder.decodeBuffer(base64string);stream=newByteArrayInputStream(bytes1);
} catch (Exceptione) {
e.printStackTrace();
}
returnstream;
}
publicstaticStringThumbnailsOperateImage(Stringbase64){
try {
InputStreambis=BaseToInputStream(base64);ByteArrayOutputStreambao=newByteArrayOutputStream();Thumbnails.of(bis).size(400, 800).toOutputStream(bao);
byte[] bar=bao.toByteArray();Stringstr=Base64.encode(bar);returnstr;
} catch (IOExceptione) {
e.printStackTrace();
}
return"";
}