简体   繁体   English

将base64编码的字符串数据压缩为解码格式

[英]compress base64 encoded string data into decode format

Hi im decoding the base64 string data and saving into the database like url format with time stamp so i need to compress the decoded data and my compression like if the coming data is less than 100kb then no need to compress otherwise compress the data into 50% off. 嗨,我将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();
}

Your main problem is probably not going to be compressing it in Java. 您的主要问题可能是不会在Java中进行压缩。 For that you can simply use something like the Deflater class . 为此,您可以简单地使用Deflater类之类的东西。 On iOS however it might be a little more complicated, as I'm not sure what kind of zlib-like tools you have available in iOS. 但是在iOS上,可能要复杂一些,因为我不确定您在iOS中可以使用哪种类似zlib的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM