Understanding Lift's StreamingResponse
March 19th, 2009
I was just looking at the Lift’s StreamingResponse and was a bit bemused by the structural type being used for the first parameter. After some fiddling around I realized that:
data: {def read(buf: Array[Byte]): Int}
This will actually make the method more flexible and not tied to a particular hierarchy of classes (and super classes). So, if your looking at Lift’s StreamingResponse and thinking “what the hell”, all you need to remember is that you can pass any thing into the first parameter as long as it implements the read method with the above signature. This, IMO, is majority cool. The default thing that implements this signature is java.io.InputStream, but you could of course pass anything – even your own custom classes!
A sample implementation might look like:
var data: Array[Byte] = // get your data here
val headers =
("Content-type" -> "application/pdf") ::
("Content-length" -> data.length.toString) ::
("Content-disposition" -> "attachment; filname=download.pdf")
:: Nil
Full(StreamingResponse(
new java.io.ByteArrayInputStream(data),
() => {},
data.length,
headers, Nil, 200)
)
So, to recap, structural types are awesome!
Are iPhone applications the latest marketing frontier?
March 1st, 2009
Recently I’ve noticed more and more iPhone applications being released in the run up to both film releases and real-world product launches for large purchase items such as cars. So, what do the marketing chaps want to achieve with these adventures into the world of mobile computing?
Can we summarize that the marketeers see the iPhone as a lot more than just a mobile device? I think so, otherwise they simply wouldnt bother right? The thing I simply cannot get my head around, is how, or indeed if, the marketeers look to get any ROI on what must be a sizable amount of time and investment to create these iPhone apps which are usually quite sophisticated games.
Rhino Ball
For example, lets take Rhino Ball – a pretty sophisticated 3D game in which you control a hamster in a rolling ball. Pretty amusing, but I cant say it really compelled me to go and see the film. So why bother? In times of recession and tight budgets, I simply cant fathom why they are spending money on this rather niche medium to touch a small group of people with a weak message.
Perhaps this is just a prime example of marketing depts. blowing budgets for the simple reason “its cool”.