[英]compress base64 encoded string data into decode format
嗨,我将base64字符串数据解码并保存到带有时间戳的url格式的数据库中,因此我需要压缩解码后的数据,并且进行压缩,例如如果即将到来的数据小于100kb,则无需压缩,否则将数据压缩到50%关。
try
{
String FileItemRefPath = propsFPCConfig.getProperty("fileCreationReferencePath");
String imageURLReferncePath = propsFPCConfig.getProperty("imageURLReferncePath");
File f = new File(FileItemRefPath+"/"+"productimages"+"/"+donorId);
String strException = "Actual File "+f.getName();
if(!f.exists())
{
if (!f.mkdirs())
{
System.out.println("direction creation failed");
return null;
}
}
else
{
boolean isdirCreationStatus = f.mkdirs();
}
String strDateTobeAppended = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
String fileName = strImageName+strDateTobeAppended;
savedFile = new File(f.getAbsolutePath()+"/"+fileName);
strException=strException+" savedFile "+savedFile.getName();
Base64 decoder = new Base64();
byte[] decodedBytes = decoder.decode(strImageBase64);
if( (decodedBytes != null) && (decodedBytes.length != 0) )
{
System.out.println("Decoded bytes length:"+decodedBytes.length);
fos = new FileOutputStream(savedFile);
System.out.println(new String(decodedBytes) + "\n") ;
int x=0;
{
fos.write(decodedBytes, 0, decodedBytes.length);
}
fos.flush();
}
if(fos != null)
{
fos.close();
System.out.println("file output stream"+savedFile.getName());
return savedFile.getName();
}
else
{
return null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if( fos!= null)
{
fos.close();
}
else
{
savedFile = null;
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return savedFile.getName();
}
您的主要问题可能是不会在Java中进行压缩。 为此,您可以简单地使用Deflater类之类的东西。 但是在iOS上,可能要复杂一些,因为我不确定您在iOS中可以使用哪种类似zlib的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.