Total Pageviews

Sunday, February 17, 2013

Fixing poor performance (lagging) on Samsung Galaxy Nexus GSM (i9250) phones

Woohoo, I can't believe it. My Galaxy Nexus phone is affected by a bug which causes the phone to slow down and to behave very laggy after a while. Some users reported this might happen when they uploaded or downloaded huge files (e.g. movies).
I can't tell whether huge files caused this problem on my Galaxy Nexus, but from one day to another the phone was reacting very slow. It was no longer usable for me. Typing a single character on the keyboard was a pain in the ass ...
I started to google around and found this posting on XDA which saved my phone's life ;-)
If you are experiencing the same behavior on your Galaxy Nexus you might consider following the steps there. But be careful not to HARD BRICK your phone, because your phone must have a special chipset.
My phone was produced in 08/2012 and really has the "suspicious" V3U00M chipset mentioned in the XDA posting. I checked it using the eMMC Brickbug Check app from the play store.
If your phone is not rooted you can't fix the problem. Either you root it now, or you send it to Samsung and let them repair/swap it. It's up to you.
The next thing to do was to run the LagFix (fstrim) free app or paid version. I now use the paid version, because it has a built in scheduler which runs fstrim every night.
The script mentioned in the posting isn't necessary if you use the paid version of LagFix.
After running the LagFix app my phone was reacting as fast as on the day I bought it and it remains fast until now.

Thursday, February 07, 2013

Multi Line Table Cells in Vaadin 6

I had a hard time figuring out how to wrap content in a table cell using Vaadin 6.7.
Content in row headers can be forced to wrap using a simple "<br/>" tag in the string. Unfortunately it isn't that simple with non-header cells.
I found a working solution in this Vaadin forum post.
You simply have to create your own CSS stylesheet definition and add the following code to it:

 .v-table-cell-wrapper {   
  white-space: normal;   
 }  

Tuesday, February 05, 2013

Howto compress and uncompress a Java byte array using JDK Deflater/Inflater

If you ever came across the requirement to store binary data somewhere (e.g. filesystem or database) it might be handy to compress those data.
Besides the common ZIP algorithm Java offers the Deflater and Inflater classes that uses the ZLIB compression library. ZLIB is part of the PNG standard and not protected by any patents.
Here is a small code snippet which shows an utility class that offers two methods to compress and extract a Java byte array.

 package de.qu.compression.demo;  
   
 import java.io.ByteArrayOutputStream;  
 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.FileOutputStream;  
 import java.io.IOException;  
 import java.io.InputStream;  
 import java.util.List;  
 import java.util.Map;  
 import java.util.zip.DataFormatException;  
 import java.util.zip.Deflater;  
 import java.util.zip.Inflater;  
   
 public class CompressionUtils {  
  private static final Logger LOG = Logger.getLogger(CompressionUtils.class);  
    
    
  public static byte[] compress(byte[] data) throws IOException {  
   Deflater deflater = new Deflater();  
   deflater.setInput(data);  
   
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);   
       
   deflater.finish();  
   byte[] buffer = new byte[1024];   
   while (!deflater.finished()) {  
    int count = deflater.deflate(buffer); // returns the generated code... index  
    outputStream.write(buffer, 0, count);   
   }  
   outputStream.close();  
   byte[] output = outputStream.toByteArray();  
   
   deflater.end();

   LOG.debug("Original: " + data.length / 1024 + " Kb");  
   LOG.debug("Compressed: " + output.length / 1024 + " Kb");  
   return output;  
  }  
   
  public static byte[] decompress(byte[] data) throws IOException, DataFormatException {  
   Inflater inflater = new Inflater();   
   inflater.setInput(data);  
   
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);  
   byte[] buffer = new byte[1024];  
   while (!inflater.finished()) {  
    int count = inflater.inflate(buffer);  
    outputStream.write(buffer, 0, count);  
   }  
   outputStream.close();  
   byte[] output = outputStream.toByteArray();  
   
   inflater.end();
   
   LOG.debug("Original: " + data.length);  
   LOG.debug("Uncompressed: " + output.length);  
   return output;  
  }  
 }  
   

It is also possible to receive better compression results by calling the method setLevel of the Deflater class and specify the constant Deflater.BEST_COMPRESSION.