Friday, August 15, 2003

Eclipse Templating

I've been using Eclipse as my primary development environmentfor about a year now. I moved over from Netbeans along with most of the development team I work in. Despite using it for a year, I've only just found out quite how powerful the template mechanism is.


The Ctl-Space code complete option also works for user definable templates and these can contain replaceable variables. For example adding a template for generating a test for a getter/setter operation on a string is as easy as follows :


Generate a new template (windows->preference, Java-Editor-Templates) with the following content named teststr


/** Test the get/set method for ${var}.*/
public void testGetSet${var}
{
${obj} obj=new ${obj}();

// do set
obj.set${var}("test value");

// check
if(!pbj.get${var}().equals("test value"))
{
fail("get/set failed for ${var}.");
}
}



Now in the source edit window type teststr then Ctl-Space. This inserts the template, typing FirstName Tab User will then insert the following into your code:


/** Test the get/set method for FirstName.*/
public void testGetSetFirstName
{
User obj=new User ();

// do set
obj.setFirstName("test value");

// check
if(!pbj.getFirstName().equals("test value"))
{
fail("get/set failed for FirstName.");
}
}


Clearly this is a simple example, but even this is a big time saver.



Tuesday, August 05, 2003

Mplayer and Streaming audio

I was talking with a pal yesterday about listening to radio streams from my RedHat 9 box. I promised I'd write up a couple of quick tips on getting it all going. I listen to most things through mplayer rather than messing around with Real Player etc.


Most radio streams are made a little hard to find by the content producers, you have to trawl through the html in the pages to get links (CTL-U) on Mozilla. If the stream is a .ram or .rmp link, use curl to open the url. The contents of that can then be passed to mplayer.


eg. The source to the bbc radio player whilst launching radio 4 shows http://www.bbc.co.uk/radio4/realplayer/media/fmg2.rpm as the link to the live stream.

Opening that url with curl gives rtsp://rmlivev8.bbc.net.uk/farm/*/ev7/live24/radio4/live/r4_dsat_g2.ra.

I then squirrel that away for future reference (they do change it occasionally) in a shell script that runs mplayer as follows :

mplayer -cache 64 rtsp://rmlivev8.bbc.net.uk/farm/*/ev7/live24/radio4/live/r4_dsat_g2.ra