TSS Symposium Preview – GWT Roundup

I'm Speaking at TheServerSide Java Symposium Google Web Toolkit As previously mentioned, Jeanne and I will both be presenting talks at TheServerSide Java Symposium exactly one month from now. Here is a preview of two of the topics I will be discussing at my talk “GWT Roundup: An Overview of Google’s Web Toolkit and Hybrid Integration” : GWT Image Bundles and Speed Tracer.

1. GWT Image Bundles

One of the more interesting features that GWT offers, beyond what most developers using indirect Ajax frameworks could build on their own, is the concept of Image Bundles. Even GWT developers who use Image Bundles may not have any notion of what is going on under the covers because the implementation details are so well abstracted. The idea is to take a large group of images and combine them into a single image with an interface for accessing each image. This may sound like a strange notion, but the performance advantages of doing so are manyfold:

  • More responsive UI since all images are downloaded together
  • Faster than downloading them individually since they are not downloaded in serial (HTTP 1.1 limits number of outgoing connections to 2 per domain)
  • Bundles use less bandwidth than separate images since multiple image headers are reduced to a single header

2. Speed Tracer

New to GWT 2.0 is the ability to validate such non-functional requirements as user interface performance, using the Speed Tracer tool, a Google Chrome extension. For example, if a particular asynchronous RPC call is causing delays in the user experience, Speed Tracer will help you identify it. Speed Tracer provides two graphs that show user response information and offers “hints” of spikes in response time that could be causing problems in your application.

  • Sluggishness Graph: Shows UI responsiveness
    GWT Speed Tracer - Sluggishness Graph
  • Network Graph: Network activity and latency
    GWT Speed Tracer - Network Graph

See you in Las Vegas!

I hope you enjoyed this preview of the talk I will giving next month. I will also be taking part in a panel hosted by Cameron McKenzie called “Client Side Development Smackdown” . Oh, and it’s not too late to register for TheServerSide Java Symposium 2011. We hope to see you there!

TheServerSide Java Symposium – Preview Week

TheServerSide Java Symposium 2011 Jeanne and I will both be presenting talks at TheServerSide Java Symposium in March. In preparation for the conference, we will be providing sneak peaks of talks this week on the blog.

I’m giving a lecture entitled “GWT Roundup: An Overview of Google’s Web Toolkit and Hybrid Integration” which provides a review of GWT for old and new GWT developers alike. It also covers many of the new features released in GWT 2.0 and 2.1. I will also be speaking as part of a panel hosted by Cameron McKenzie called “Client Side Development Smackdown” .

Jeanne’s presentation is called “Throw Away All The Rules. Now What Process Do You Follow?” and is about what processes are important if you aren’t being forced to follow any. It uses the CodeRanch forum conversion project as an example.

It’s not too late to register for TheServerSide Java Symposium 2011. We hope to see you there!

Creating a tar.gz file in Java

Today’s article demonstrates how to create a tar.gz file in a single pass in Java. While there’s number of websites that provide instructions for creating a gzip or tar archive via Java, there aren’t any that will tell you how to make a tar.gz file without performing the same operations twice.

Reviewing Tar and Gzip Compression

First, download the Apache Commons Compression library. It is actually a subset of the code found in the Ant Jar for those performing compression operations that do not require all of Ant’s many features. Below is the code to create a tar and gzip archive, respectively, using the Compression library.

TarArchiveOutputStream out = null;
try {
     out = new TarArchiveOutputStream(
          new BufferedOutputStream(new FileOutputStream("myFile.tar")));
     // Add data to out and flush stream
     ...
} finally {
     if(out != null) out.close();
}
GZIPOutputStream out = null;
try {
     out = new GZIPOutputStream(
          new BufferedOutputStream(new FileOutputStream("myFile.tar")));
     // Add data to out and flush stream
     ...
} finally {
     if(out != null) out.close();
}

One subtlety in this example is that we use a BufferedOutputStream on the file stream for performance reasons. Often, archive files are large so that buffering the output is desirable. Another good practice is to always close your resources in a finally block after you are done with them.

The Solution

The solution is to wrap the tar stream around a gzip stream, since the order of writing goes inward from outer most to inner most stream. The code below first creates a tar archive, then compresses it inside a gzip stream. Buffering is applied and the result is written to disk.

TarArchiveOutputStream out = null;
try {
     out = new TarArchiveOutputStream(
          new GZIPOutputStream(
               new BufferedOutputStream(new FileOutputStream("myFile.tar.gz"))));
     // Add data to out and flush stream
     ...
} finally {
     if(out != null) out.close();
}

You can then treat the stream as a tar file using the TarArchiveEntry API to add entries and write data directly to the stream. The gzip compression will happen automatically as the stream is written.