Wednesday, November 17, 2010

Capital IQ - Moving To McGraw Hill Financials

In a move to foster innovation and drive growth, The McGraw Hill Companies (NYSE: MHP) announced several Organizational and Management changes a few days back (November 15th 2010).

Though there are a few Management changes, I will be mostly stressing on the Organizational changes here. From a bird's-eye view, the current financial services of McGraw-Hill will be realigned into two segments - Standard & Poor's and McGraw-Hill Financials.

Currently, McGraw-Hill Companies is divided into three segments -

  1. Financial Services which includes Standard & Poor's Credit Market Services and S&P Investment Services (which includes Capital IQ)
  2. McGraw-Hill Education
  3. Information & Media

Beginning January 1st, 2011, McGraw-Hill Companies' reporting segments will be -

  1. Standard & Poor's - the leading credit rating company
  2. McGraw-Hill Financials - combining Capital IQ (including ClariFI, Compustat, etc.), S&P Indices, Valuation & Risk Strategies and Equity Research Services
  3. McGraw-Hill Education - the world's premier education services company
  4. McGraw-Hill Information & Media - a global business information company

The words of Harold McGraw Hill III, President and CEO of the McGraw Hill Companies on the strategic decision -

"This change will enhance our ability to deliver a broad and deep suite of products for investors across asset classes around the world, positioning us to capitalize on the growth trends we see in the global financial markets."

Check out the official announcement here. Coming to the impact of this decision on the Capital IQ brand - I guess our tagline "A Standard & Poor's Business" might change accordingly. However, there hasn't been any official confirmation on this. I will post in an update if we have anything.

Monday, November 15, 2010

RockMelt - Will Melt Your Heart

In my previous post I said I would be writing about Hibernate in this article, however I made an exception to write about a new browser I just started using - RockMelt. RockMelt is a social media web browser developed by Tim Howes and Eric Vishria and backed by Netscape founder Marc Andreessen.

It wouldn't be an overstatement if I say that it will melt your heart, especially if you're into social networking and particular a regular Facebook user like me. Here's how RockMelt looks like -

By this time, I guess most of you must have realized that it looks pretty much like Google Chrome. In fact it is more-or-less Chrome itself. Developers who have been interested in Google Chrome would have heard about Google's Chromium project - the open source project from which Chrome was born. Chromium was the parent of browsers like Nickel and now RockMelt.

However RockMelt was built to target a specific crowd - the Social Networking generation, especially users of Facebook and Twitter. Let me highlight a few features of RockMelt which I found interesting -

Friends Strip

RockMelt integrated Facebook's chat application directly into the browser as a strip running in the left side. The chat UI is pretty impressive; in fact it is as good as Google Talk. The best part is that each chat window now runs as a desktop app independently of the browser allowing users to use chat windows individually like Google Talk.

Status Updates

Updating your status in Facebook is just a click away from any site. With RockMelt, you need not actually go to Facebook to change your status or share a link. The browser itself allows you to do it.

RSS Feeds

The best thing I liked about RockMelt was its integration of RSS/ATOM feeds with the browser itself. Though many browsers manage feeds, nothing can beat this. The integration of the feeds as a strip to the right is really awesome. By default, feeds of Twitter and Facebook are built into the browser. Feeds from other sites like Gmail and Blogs can be added easily.

For people who use browsers only for surfing the web and reading articles, these changes won't be much and the regular Chrome browser should be enough. But people who are into Networking, Blogging, etc. will find it exciting and might enjoy it.

RockMelt was released a few days back and is presently “By Invitation” only and if you are interested, you should register yourselves here for an early access - http://www.rockmelt.com/. Lucky I got an invitation from one of my friends :). So if you want to try it, either register at the mentioned site or catch hold of a friend who already has an invitation :D.

Know more about RockMelt straight from the horse's mouth -

I will back on Hibernate and ADO.NET Entity Framework in my next two posts. Until then Happy Facebooking and Happy Twittering :)

Friday, November 12, 2010

Object-Relational Mapping

Over the years we have seen a paradigm shift in Programming Languages from the traditional Procedural programming approach to an Object-Oriented approach. However Databases have changed very little in terms of their fundamental principle - Set Theory. Databases are and have been Relational almost from their advent. Most of the Database Management Systems which we use like MySQL, Microsoft SQL Server and Oracle are Relational to a very large extent. Though there have been approaches like Object-Relational DBMS and Hierarchical DBMS, they have rarely been adopted in production environments.

This article focuses on creating a relationship between Object-Oriented Programming Languages and Relational Databases through a concept called Object-Relation Mapping. This article will be followed by two related articles - Using Hibernate in Java with NetBeans and Using ADO.NET Entity Framework in .NET (C#) with Visual Studio.

Before jumping into ORM, here are two common concepts which most of you must be familiar with -

Class - A class is a construct that is used as a blueprint (or template) to create objects of that class. A class defines the properties that each and every object possesses.

Table Schema - A table schema primarily defines the fields and relationships of a table. A table contains records which have the same structure.

Observing closely, we can notice that these two definitions are pretty similar. Both of them talk about a template which multiple instances follow (objects in OO and records in DBMS). Both of them talk about fields (properties) these instances possess.

This similarity is the basis of ORM. Table Schemas of Relational Databases correspond to Classes in an Object Oriented Programming Language and Records of these tables correspond to instances of the Classes (Objects).

Consider an example of a Student table in a Database created with the following schema -

CREATE TABLE Student_tbl
(
StudentId INT PRIMARY KEY,
Name VARCHAR(MAX),
Age INT
)

This table can be translated into a Class with the following structure -

class Student
{
Int32 StudentId;
String Name;
Int32 Age;
}

Each record of the Student_tbl will be an object of the Student class.

There are several free and commercial packages for Object Oriented languages that perform Object Relational Mapping. Most of these packages incorporate advanced features like -

  • Automating the class generation process from the Database Schemas
  • Maintaining foreign key dependencies using Lists
  • Generating identity keys while inserting records and using these keys in subsequent insertions as foreign keys if required
  • Creating methods for retrieving data and saving data directly as objects

The major advantages of ORM lie in -

  • Minimal database dependency - most of the ORM packages use a concept called 'Dialect' to identify the DBMS the application is connecting to. So changing the dialect when the DBMS is changed is sufficient for the application to run. No application code has to be changed
  • ORM reduces the amount of code that needs to be written by a developer

However it is often argued that ORM packages don't perform efficiently during bulk deletions and with joins. So generally it is recommended to check if there a hit in the efficiency of the application when ORM tools are introduced, especially when complex operations are involved.

Though ORM is a simple concept, it's a rapidly over-shadowing the traditional database connectivity models in Object Oriented Programming Languages like Java and C#. In my next post, I will be introducing Hibernate - an ORM package for Java and in the subsequent post I will introduce the ADO.NET Entity Framework - an ORM package for .NET.

Sunday, September 26, 2010

Standard Compression Scheme For Unicode (SCSU) - Java & .NET Implementations

In the previous article, I introduced the compression techniques available in SQL Server and highlighted the Unicode Data Compression feature of SQL Server 2008 R2. This post will cover the algorithm used by SQL Server for Unicode compression.

The Java and .NET (C#) implementations of the algorithm have been attached to the post. They have been built as Class Libraries to support reusability.

Standard Compression Scheme for Unicode

As evident from the post title, the algorithm used in Unicode Data Compression is the Standard Compression Scheme for Unicode (SCSU). SCSU is a technical standard for reducing the number of bytes needed to represent Unicode text. It encodes a sequence of Unicode characters as a compressed stream of bytes. It is independent of the character encoding scheme of Unicode and can be used for UTF-8, UTF-16 and UTF-32.

I am not going to explain the entire SCSU algorithm here but you can get its specifications from the Unicode Consortium. The SCSU algorithm processes input text in terms of their Unicode code points. A very important aspect of SCSU is that if the compressed data consists of the same sequence of bytes, it represents the same sequence of characters. However, the reserve isn’t true; there are multiple ways of compressing a character sequence.

Applications/Organizations using SCSU -

  • Symbian OS uses SCSU to serialize strings
  • The first draft of SCSU was released by Reuters, a news service and former financial market data provider. Reuters is believed to use SCSU internally
  • As already mentioned, SQL Server 2008 R2 uses SCSU to compress Unicode text

To be honest, SCSU has not been a major success. There are very few applications which need to compress Unicode Data using a special compression scheme. In certain situations, especially when the text contains characters from multiple character sets, the compressed text can end up being larger in size than the uncompressed one.

SQL Server and SCSU

SQL Server stores data in the compressed format only if it occupies lesser space than the original data. Moreover there must be at least three consecutive characters from the same code page for the algorithm to be triggered.

A major issue with the implementation is determining whether the stored text is in compressed or uncompressed format. To resolve this issue, SQL Server makes sure that the compressed data contains an odd number of bytes and adds special case characters whenever required.

The SQL Server implementation details are from a blog post by Peter Scharlock, a SQL Server Senior Program Manager.

SCSU Implementation

Though the specifications of SCSU are pretty compressive and a sample Java implementation is available at the Unicode Consortium, the implementation isn’t reusable as it is built as a Console App.

Using the specification and the sample Java implementation, I built a similar implementation as a Class Library to encourage reuse. The implementation is available in two languages - Java and C#.

The Java implementation is made available as a NetBeans project and the .NET implementation is made available as a Visual Studio solution. The implementations come along with a sample Front End which uses the corresponding Class Library.

If you are planning to modify the source code of the implementations, please keep these points in mind -

  • The .NET implementation differs from the Java implementation on a basic fact that the byte in Java is signed and the byte in .NET is unsigned. sbyte is available in .NET but using byte is more comfortable
  • Both the implementations have been tested for UTF-16 Little Endian encoding schemes. Since the default behavior of a Unicode character in Java is Big Endian, a few tweaks have been implemented

Example

To check the integrity of the SCSU implementations, a sample text file contains text from German, Russian and Japanese (the same text available at the SCSU specifications site) is taken and verified if the compressed text is as expected. The size of the file was compressed from 274 bytes to about 199 bytes.

The source code of the Java and .NET implementations can be found here. If you find any bugs, please let me know and I will make the necessary modifications.

Friday, September 17, 2010

Unicode Data Compression In SQL Server 2008 R2

SQL Server 2008 R2 was released a few months back and one of the features I found interesting was its ability to compress Unicode data. In this post, I will be introducing the various compression options available in SQL Server and towards the end I will emphasize a sample analysis used to estimate the efficiency of Unicode Data Compression and the Compression-Ratio improvements of SQL Server 2008 R2 over SQL Server 2008.

In my next post, I will emphasize on the actual algorithm used by SQL Server to achieve this compression and will provide the Java and .NET implementations of the algorithm.

Compression Techniques in SQL Server

In computer science, compression is the process of encoding information in fewer bits than an un-encoded representation would use. The compression techniques available in SQL Server can be broadly categorized into two types depending on the way they are architected - Data Compression and Backup Compression.

Data compression occurs at runtime, the data is stored in a compressed form to reduce the disk-space occupied by a database. On the other hand, backup compression occurs only at the time of a backup and uses a proprietary compression technique. Backup compression can be used on a database that has already undergone data compression, but the savings might not be significant.

Data compression is again of two types - Row level Data Compression and Page level Data Compression. Row level compression primarily turns fixed-length data-types into variable data-types, thereby saving space. It also ignores zero and null values saving additional space. Because of this, more number of rows can be accommodated in a single data page. Page level compression initially performs Row Level compression and adds two additional compression features - Prefix and Dictionary Compression. As evident, page level compression offers better space saving than row level compression.

Though compression can provide significant space saving, it can also cause severe performance issues if misused. For further reading on compression, refer "An Introduction to Data Compression in SQL Server 2008".

As the name suggests, Unicode Data Compression comes under Data Compression, and to be more specific it's a part of Row-level Compression.

Sample Analysis

Microsoft had promising stats on the Unicode Data Compression in SQL Server 2008 R2, going up to a 50% space savings on a few character sets like Hindi, German, etc. So I decided to give it a try myself.

Being from India, I decided to test the compression ratios for Hindi text. I created a randomizer in C# (.NET) to generate random text from a few Hindi phrases obtained from Linguanaut. The program generates 1.5 million random Hindi strings and writes them into a temporary file which is Bulk Inserted into a table.

To check the improvement of SQL Server 2008 R2 over SQL Server 2008 in terms of Data Compression, two separate instances of SQL Server were established on the same system configuration (Intel Core 2 Quad and 4 GB RAM). Both the instances had the same schemas for the databases and the tables. The Randomizer and the Schemas + Bulk Insert scripts are attached below.

A major drawback of Unicode Data Compression in SQL Server 2008 R2 was that it couldn't be applied on columns of the data type NTEXT and NVARCHAR(MAX) and to highlight this we used two different tables, one using NTEXT and another using NVARCHAR(250).

Here is a quick reference table of the compression-ratios obtained in the analysis -

SQL Server 2008
SQL Server 2008 R2
NTEXT
98.24%
98.25%
NVARCHAR(250)
95.68%
57.78%

From the above table, we can observe the compression-ratio for Unicode Data in SQL Server 2008 R2 is around 57% (nearly the space saving mentioned by Microsoft). However in all the other cases, we can observe that the saving savings is almost negligible. For space savings of other character sets refer "Unicode Compression (MSDN)".

Get the Visual Studio Solution of the Randomizer and the Database Scripts here.

SQL Server 2008 R2 Screen Shots

SQL Server 2008 Screen Shots

Sunday, August 22, 2010

Creating A Bootable Windows 7 USB Flash Drive

In this post, I am going to emphasize on how to create a bootable USB drive with the Windows 7 installer. It's a pretty simple and straight-forward process. There are several advantages of doing this -

  • Installing Windows 7 on computers without an Optical CD/DVD Drive. Many of the new laptops/desktops come without the CD/DVD drive. Using a bootable USB is very helpful here
  • Installing from the USB drive is typically faster than installing from a DVD drive
  • OS disc images (.iso, .nrg) need not be burned onto a CD/DVD to use them. You can make a bootable USB drive from the image and install the OS from the USB

There are two phases involved in the process - "Formatting the USB drive" and "Copying the installation files and making it bootable".

Formatting the USB drive

I am using the Diskpart command line utility in the following steps to format the USB drive. I guess even the Right-click and Format option can be used, but I haven't tried it. If you get into any trouble using the Format from the Right-click menu, put in a comment and I will look into it.

  1. Open the command prompt as an Administrator
  2. Start the DiskPart utility by typing in "diskpart". This will show a list of all the drives connected to the system. Identify the disk corresponding to the USB drive
  3. Select the USB drive using the "select ###" command
  4. Clean it using the "clean" command
  5. Create a primary partition on the USB using the "create partition primary" command. This is where we will be copying the installation files
  6. Select the partition using the "select partition 1" command
  7. Make it active by typing "active"
  8. Format the drive and create an NTFS filesystem on it using the "format fs=ntfs" command
  9. Assign a drive letter to the USB disk using the "assign" command
  10. Exit the DiskPart utility using the "exit" command

The USB is now formatted and is ready for the transfer.

Copying the installation files and making it bootable

The following steps are the crux of the process.

  1. Insert the Windows 7 DVD
  2. Navigate to the boot directory of the DVD
  3. There is a utility "Bootsect" which comes bundled in the Windows 7 DVD. This does the entire work for us
  4. Run the utility from the command line and specify the drive letter of the USB drive. bootsect.exe /NT60 X:
  5. The utility adds the appropriate boot-code to the USB drive
  6. Copy the contents of the DVD onto the USB drive

That's it, reboot the system, make sure that the USB boot is given the highest priority and the installation starts.

Saturday, August 07, 2010

Community TechDays August 2010

I spent my entire day today at Microsoft IDC, Hyderabad where I had a wonderful experience at Community TechDays organized by the Microsoft User Group, Hyderabad (MUGH). For people wondering what Community TechDays is - It is a multi-city event conducted quarterly by the technology community for Developers, Infrastructure Professionals, Architects, Project Managers and Students. This was the fourth Community TechDays series in India but the first one I attended.

The event started at around 9:30 and there were two parallels tracks - one for the Developers and another for the IT Professionals. Having registered for both, I attended the sessions which I found interesting in the two tracks. On a whole there were 5 sessions which I attended. I will give a brief description of the sessions I attended and will try to get the technical details on my Tech Blog sometime soon. But no promises on that :)

The first session was on the Data compression options in SQL Server 2008 by Arun Shankar which was pretty good. It covered how the database can be compressed during backup and various data compression techniques like row level compression and page level compression to reduce the size taken up the database. Following that was a session on IIS End to End by Muqeet Khan. To be honest, I didn't have much experience on IIS but had a reasonable exposure to web servers as a whole. So learnt a lot through the session and loved the concept of running languages like PHP and Java in IIS 7.0.

The next session I attended was on Cloud Services with Windows Azure Platform by Arun Ganesh. This was one session where content was very good but time was a major constraint. Initially he started with an introduction on Cloud Computing and a live demo on developing and deploying a sample application on Windows Azure. He also covered Azure Storage - Tables, Blobs and Queues with a live example. Though he introduced SQL Azure and Azure Services like Service Bus and Access Control, he couldn't cover a live example there. As I had prior experience in developing and deploying an Azure app, I was really looking forward for the demo on Service Bus and Access Control but was a bit disappointed at the end.

Post lunch, there was a session on WCF in .NET 4.0 and Windows Server AppFabric by Phani Kumar. This was a bouncer for me. With negligible hands-on experience on WCF, the session was way above my head. Though the speaker was explaining it well, me and my friends had a tough time co-relating it to what we did. The last session was more like an open discussion again with Muqeet Khan. It started with batch processing admin tasks in Power Shell and soon moved on how Windows works. It was more like a refresher of my OS class at college but more entertaining :D

The day ended with a curtain raiser of XBox Project Natal (more popularly known as Kinect for XBox 360) at around 4:30. I can't wait to get my hands on it when it comes to India in December this year.

Oh, the best part of the day - I guess we were among the youngest developers who came for the event today. It was actually interesting sitting in a crowd with people with work-experience of around 2-3 years with our work-experience of around 2-3 months ;)

Thursday, July 22, 2010

Ciao, Osmania University

It's been more than a month I left Osmania University and day after day I see my friends spread out to pursue their careers. But, whenever I go back in time, several sweet memories flash by before my eyes. To be honest, it's a little heart-breaking to realize that the college which I claimed to be mine is no more mine. But I still have what Osmania University has given to me - a whole lot of friends and a wonderful experience :)

One thing I understood at the end of this post was that these were the most happening four years of my life and I will definitely miss them :(

Four years back, I never thought that this time span would be over as quickly as it did. I still remember the day when I was at the EAMCET counseling, heart filled with anxiety, not sure which college I would get into and the seat-counters of various colleges go down one by one. As destiny wanted, I ended up at Osmania University, College of Engineering and then began a whole new chapter in my life.

Every one of these four years was special in its own way. In the first year, we were "The Juniors", with an unofficial formal dress code and living under the shadows of the seniors. To be honest, it wasn't as bad as it sounds. My seniors were really good and they did help us a lot and supported us when required. We also managed to learn several things from them over the years – both in terms of technology and event management. The first year ended with a magnificent freshers week at the "Landscape Gardens" and the freshers party at "Sixth Element".

Second year, we were "The Seniors" ;). We managed to have a lot of interaction with the our juniors and over a period of time we made a lot of friends among them. We had a lot of free time in the second year and even started bunking classes :D. We started exploring the college and spent a lot of time at the "Caroms Room". The second year ended with another freshers week and the freshers party at "F-Bar". I enjoyed making the freshers DVD and it will truly be one of my cherished possession of Osmania University.

All the career decisions began in the third year. A lot of my friends started taking up coaching for GATE and CAT. I was more focused towards taking up a job and didn't pursue either of the two. I joined Sun Microsystems Inc. as a Campus Ambassador (Technical Evangelist) in my third year and spent a year and a half working in it. Third year was a serious year concentrating on education and careers. And of course, the "Cricket Ground" :D. The third year ended with an Industry Attachment Program with Sun Microsystems Inc.

The fourth year was the fastest to pass by. Starting with a deep worry about job opportunities thanks to the recession impact in the country, it went by with me and my friends searching for jobs and spending countless moments at the "Placement Cell". Within a few months, the competitive exams like CAT and GATE came by and most of my friends were completely occupied with them.

Classes, Jobs, Exams and a little Fun - This is what fourth year was. And over and above all this, the Telangana Agitation ;). I even started my internship during the latter half of the fourth year along-side my final year project. I was literally beseeching for time the six months, but I believe it was worth the effort.

Over these years, I had several moments of fun and joy; and a few moments of sorrow and regret. But thinking back, I actually enjoyed each and every one of those moments. Well, time can never come back but it is the memory of these moments which brings about a warm smile on our faces.

Before I sign off, I would like to thank everybody whose has been a part of my college life over these years for giving me such a wonderful time and my sincere apologizes to anyone whom I have hurt knowingly or unknowingly. My deepest gratitude to the entire faculty for their guidance and putting up with all the juvenile things we have done. Wishing everyone the best of luck in their future endeavors and with a bright hope that our paths will cross again, Good Bye.

Thursday, July 15, 2010

Technology Team Outing 2010

Last week, the entire technology team of Capital IQ, Hyderabad went to Lahari Resorts. CIQ has a tradition wherein every year, every team goes out to a vacation spot to relax and enhance team bonding. So following the lines of this tradition, the technology team geared up this year to visit Lahari Resorts. The best part of this tradition is that the new joinees are responsible for the co-ordination of the entire event. Having joined Capital IQ last month as a fresher, the responsibility of organizing the event was on us and we had a great time organizing it :)

If you have already read Aishwarya's blog-post on the outing, this post may seem redundant, but before leaving, check out the photo show embedded at the end of the post. If you haven't read it, "Read On!".

After a lot of discussions and putting in a lot of thought, we selected Lahari Resorts for this year. Like any event, the major focus was on transportation, food, publicity and event management.

To lighten up the spirits of the team, we planned a few in-office events the day before the outing. We conducted various fun activities like "Logo identification" and "Recognizing the blurred images of various celebrities". To be honest, I never expected anybody to participate, but it was delightful to see people spare time from their work and participate in the events. And judging from their enthusiasm, I guess they had they had a very good time. We also designed posters and digital invitations to unleash the fervor.

The following morning, the D-day arrived, we all assembled in the office and moved on to the resort. Buses were arranged for people who didn't have their own vehicles. I went in a car, as me and a few others planned to reach a bit early so as to take care of the arrangements at the venue. From what I heard, the people in the bus had a wonderful time. Damn, I missed it :(

Once we reached the venue, we were in for the shock of our lives. The entire team had planned something for us, "The Freshers" - An Interaction. We were asked to introduce ourselves and do something - sing, dance, act, anything. For people wondering what I was asked to do - "Introduce myself in pure Telugu" (no laughing please ;)) and narrate a dialogue from a popular Telugu movie.

One thing which everybody in the office were waiting for were the Cricket tournaments. We booked a ground for ourselves and had several Cricket matches. In parallel a few of us played football and a few went directly into the pool.

After a few matches of Cricket and Football, we all plunged into the swimming pools. As the evening progressed, we assembled for a pool-side dinner. Simultaneously the dance-floor was opened. I personally felt that the Disco was the best part of the day. Initially a lot of people refrained from the dance-floor but eventually most of them ended up on it. It was nice to see people coming out of their shells and join us :)

We partied all night long and I reached home at midnight. I had a wonderful time and am enthusiastically waiting for the next party ;).

It would be unfair if I conclude without introducing the guys and girls who have made the event memorable - Aastha, Aishwarya, Anindya, Ankit, Arnav, Dinesh, Karthik, Niya, Preeti, Rajashree, Rohan, Sandhya, Sasikiran and Sudha - "New Joinees 2010" (Jame and Simanta - we missed you both)

And kudos to Raghu Vamsi, a year senior to us at CIQ, for his inspiring guidance through-out the event organization. Also my sincere regards to the entire Technology Team for making the night unforgettable.

And here's a small photo slide-show of the two days -

Saturday, July 10, 2010

Integrating OACurl With A Java Desktop Application

In my previous post, I introduced the Google Buzz API and the technologies surrounding it. In this post, I will be emphasizing on how to integrate OACurl with a Java Desktop Application to make the authentication process simpler. Before I continue, let me categorical state that this method is good for small student projects; but for serious production applications, OACurl integration isn't a good option.

OACurl is primarily an OAuth aware wrapper around the popular cURL command line utility. If you are wondering what cURL is, it is a software project providing a library and command-line tool for transferring data using various protocols like HTTP, FTP, HTTPS, LDAP, IMAP, POP3, etc. The beauty of cURL is that it simplifies the process of data transfer using these protocols to a very large extent. OACurl is an extension to this utility which supports OAuth, the authentication/authorization protocol of the Google Buzz API. OACurl provides an easy way to experiment with the Buzz API.

Before I start with OACurl Integration, let's see how we can connect a desktop application to the Google Buzz API without OACurl. As I mentioned in the previous post, the OAuth token request and authorization process takes place through a Web Browser. So the desktop application should open the Browser and allow Google to verify the user credentials. Then Google issues an authorized token to a Callback URL as specified by the application. This has to be detected by the application and it has to regain focus. For a more detailed view on this, check out - http://code.google.com/apis/accounts/docs/OAuthForInstalledApps.html.

The biggest challenge in this process is that in devices like Gaming Consoles, Setup Boxes, etc., where a Web Browser isn't available the entire procedure goes haywire. Google is working on a solution for this, until then we have to adjust with the Web Browser technique.

OACurl is a pretty easy tool to work with. It is available as a Java Archive with multiple classes for various operations like Logging in, Fetching data from URLs, etc. To use OACurl directly from the command-line, refer http://code.google.com/apis/buzz/v1/oacurl.html.

To use OACurl within a Java Desktop Application, add a reference to the jar file from your project. Now there are two classes which do the entire thing for us - Fetch and Login. Both of them contain a main method; actually it is these classes that are being used in the URL mentioned above. But instead of using classes from the command-line, we will directly call the main method in them from our Java program.

A bit of reverse engineering makes it clear that the flags like "-buzz", "-X", "POST", etc. are being sent as command line arguments. So we can create a String array of these flags and sent it to the main method.

com.google.oacurl.Login.main (new String[] { "-buzz" });
com.google.oacurl.Fetch.main (new String[] { "-X", "POST", URL });

The main methods push the output content to the default output stream as specified by System.out. By default, this is the user screen. If we want to use this output, we can transfer this output into a temporary file and read from this file.

File temp = File.createTempFile ("output", null);
PrintStream output = new PrintStream (temp);
System.setOut (output);

Similarly, the main methods read the input from the default input stream as specified by System.in. By default, this is the keyboard. If we have to send our input, we can create a temporary file, write the content into it and make the file the default input stream.

File temp = File.createTempFile ("output", null);
// Write into the file
PrintWriter writer = new PrintWriter (temp);
System.setIn (writer);

This way we can use the Google Buzz API within our Java Desktop Application without having to worry anything about the authorization process. Developers curious to know how this works can explore the OACurl project hosted on Google Code at http://code.google.com/p/oacurl/. The complete source code of the Login and Fetch classes as well as the Callback Server and other classes is available at the link.

Before I wind up, here is a small project developed in NetBeans which reads the latest buzz and publishes buzz content.