As you might know I am a cineast and a home theater junkie. I have tried to assemble a decent home theater. From time to time I upgrade it to achieve the ultimate movie experience. For several years now, I have been longing for a Blu-ray player. However I do not like to be a early adopter, at least when it comes to hardware. The primary reason is that it is to expensive, the secondary is that the technology needs to be mature enough for me to buy it. In this case it was in fact Java that stopped me. Why? Let me explain.
A Blu-ray player manufactured today is required to include a Java implementation to adhere to the Blu-ray specification. This is called BD-J. The intention with this is to be able to include more advanced menus, games and interactive contents. A Blu-ray disc can contain one or several Xlet applications. For a more comprehensive article on the subject, please download and read my article "Blu-ray and Java". When the MIDlet specification was released, it took several years before there was a decent implementation available. As it seems, it is the same with Xlet implementation on Blu-ray players. Many independent Blu-ray player reviews shows that Blu-ray discs with Java content have longer loading time. For example, it is reported that loading time up to several minutes is not unusual.
The July issue of the Swedish magazine "HemmaBio" contained a big review of several Blu-ray players. The LG BD370 was dubbed "Best Buy" and at a reasonable price. I searched the Internet and found several positive reviews, like this one. Besides the price, it seemed to have very good Java performance. In fact it is par with the performance of a Playstation 3 when it comes to loading times for Blu-discs. It adheres to the latest BD-J version and also has support for BD live. The BD live feature is used to bring live content to your Blu-ray player, such as trailers. For example, the "Transformer" movie let you connect to the Internet and download the trailer for the following "Transformer" movie. Another nice feature is the YouTube viewer. As you might have understood by now, I bought the LG player.
To try the player I bought two Blu-ray discs. I decided one disc while I let my son decide the other one. My choice was the "Pirate of Caribbean: the curse of the black pearl". This is by many considered as a reference Blu-ray disc. Both the picture and sound are great, but it also contains BD-J content. The BD-J content is used for testing the performance on Blu-ray players, since it is rather big. As mentioned before, it could several minutes to load the content. My son choose the movie "Bolt", just because it contained a game. It was a special edition that also contained the DVD version. So this was perfect to test a Java game and to compare the quality difference between the DVD version and the Blu-ray version. Both the picture and sound is considerable better.
I think it is interesting to see Java on yet another platform. It shows how Java is usable in many different environment. Java is finally used in an environment similar to the environment it was originally designed for, that is set-top boxes.
Here are some pictures from me using the new Blu-ray player.
The main menu when starting the Blu-ray player.
The featured videos on YouTube.
The search screen, while searching for the Jayway video.
The Jayway video in normal screen mode.
The Jayway video in full screen mode.
The Bolt game. Notice the localized version. I have not seen this on many computer games today. In the beginning of the game, the instructions are narrated. This is good for kids that could not read.
Aug 27, 2009
Aug 25, 2009
Appending to a File in Java ME ( J2ME )
Yesterday I was asked how to append to a file in Java ME. I have never done this before, so I could not give an answer. After some research we found a working solution. This article will go through the different ways to solve it.
I first looked into the JSR-75 documentation, but I did not find any solution there. When searching the Internet, the first solution I found was this:
The next solution I found looked like this:
This works but is rather clumsy and does not look clean. Note that you need to call
The method openOutputStream(long bytesOffset) open an OutputStream and moves the position the specified offset. When the offset is greater than the file size, the position is moved to the end of the file. This is an clean and portable solution.
I first looked into the JSR-75 documentation, but I did not find any solution there. When searching the Internet, the first solution I found was this:
At first it looks promising. The
public void appendToFile() {
try {
FileConnection fileConnection = (FileConnection) Connector.open(
"file:///c:/other/textfile.txt;append=true",
Connector.WRITE);
OutputStream outputStream = fileConnection.openOutputStream();
PrintStream printStream = new PrintStream(outputStream);
printStream.println("Some text to append");
} catch (IOException e) {
e.printStackTrace();
}
}
Connector
class specifies that you could add parameters when opening a connection. However the parameters for JSR-75 are not standardized. This solution was mentioned in the Nokia developer forums, so I guess that it works on Nokia phone. The platform that we uses did not support it. Thus this solution is not portable across different Java ME devices. I recommend that you DO NOT use a solution like this.The next solution I found looked like this:
public void appendToFileFileSize() {
try {
FileConnection fileConnection = (FileConnection) Connector.open(
"file:///c:/other/textfile.txt", Connector.WRITE);
OutputStream outputStream = fileConnection.openOutputStream();
outputStream.flush();
long fileSize = fileConnection.fileSize();
String textToAppend = "Some text to append";
outputStream.write(textToAppend.getBytes(), (int)fileSize, textToAppend.length());
} catch (IOException e) {
e.printStackTrace();
}
}
This works but is rather clumsy and does not look clean. Note that you need to call
flush()
before you make a call to fileSize()
, otherwise the size is not guaranteed to be correct. But wait, there is another solution.
public void appendToFileMaxLong(){
try {
FileConnection fileConnection = (FileConnection) Connector.open(
"file:///c:/other/textfile.txt", Connector.WRITE);
OutputStream outputStream = fileConnection.openOutputStream(Long.MAX_VALUE);
PrintStream printStream = new PrintStream(outputStream);
printStream.println("Some text to append");
} catch (IOException e) {
e.printStackTrace();
}
}
The method openOutputStream(long bytesOffset) open an OutputStream and moves the position the specified offset. When the offset is greater than the file size, the position is moved to the end of the file. This is an clean and portable solution.
Labels:
Java ME,
Tips and Tricks
Subscribe to:
Posts (Atom)