Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
BlueBerry1988
Posts: 157
Registered: ‎03-03-2009
My Device: Not Specified
Accepted Solution

Long String text and cod file size

In my application, I have a few static string constants that are very long. The strings will be displayed on screen when given buttons are clicked. I find out that once I added these strings, the cod file size increased by 30% which is undesirable. I expect those buttons will rarely be clicked but I have to have those text for viewing.

 

Is there a better way to handle these strings so that they do not inflate cod file, e.g., compress them.  

 

Thanks in advance.

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Long String text and cod file size

Have you tried keeping these Strings in a separate resource file(textfile) and read it from your application when you need it.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Long String text and cod file size

If you put the strings in a separate resource file like BBDeveloper suggests, you can also run them through gzip with maximum compression before adding them to the project. Then after opening the file (with getResourceAsStream), wrap the input stream in a GZIPInputStream before reading it.



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
yogeswaran
Posts: 69
Registered: ‎07-30-2009
My Device: Not Specified

Compress and decommpress

[ Edited ]

public String  CompressData(String dataToCom)
    {
       
            byte[] data23 = dataToCom.getBytes();
            System.out.print(" data23.length()"+ data23.length);
            try
            {
               
                
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                GZIPOutputStream gzipStream = new GZIPOutputStream( baos, 6, GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH );         
                gzipStream.write( data23 );
                gzipStream.close();
                byte[] compressedData = baos.toByteArray();
                String CompressedDataString = new String (compressedData);
                
                
                return   CompressedDataString;
             }
            catch (Exception e)
            {
                System.out.print("Exceptiomn"+e);
            }
            return   null;
    }

    public String DecompressData(String dataToDecompress)
    {
        try
        {
            
            byte[] data= dataToDecompress.getBytes();

    // the Data.leng must be as same as the original String length not as the copressered data length .....
            ByteArrayInputStream bais= new ByteArrayInputStream(data,0,data.length);
            
            GZIPInputStream gzis = new GZIPInputStream(bais);
            
            StringBuffer sb = new StringBuffer();
            int  c;
            while ((c = gzis.read()) != -1)
            {
                char cc = (char)c;
                sb.append(cc);
            }
            String DecompresedData = sb.toString();
            return DecompresedData;
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return null;
    }

Please use plain text.