I’ve added some notes on video screen capture for software demos over on Random Tech Notes. This isn’t strictly Java-related, though I’ve been experimenting with screen recording in the context of capturing a Java application that has animation and audio synchronized to user interaction, two factors that complicate the task a bit.
On upgrading a piece of (1.4-dependent) server-side software from 1.4.2_01 to 1.4.2_14, I began seeing errors that looked like:
java.awt.HeadlessException at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice (HeadlessGraphicsEnvironment.java:66) at javax.swing.RepaintManager.getVolatileOffscreenBuffer (RepaintManager.java:537) at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4727) at javax.swing.JComponent.paint(JComponent.java:798) at edu.vt.cs.collab.cork.impl.servlet.CORKServlet.encodeComponentAsJPEG (CORKServlet.java:617) at org.isenhour.fin.inc.CEFChartWebView.writeChartImage(CEFChartWebView.java:97) at org.isenhour.fin.inc.CEFChartWebView.writeStaticContent(CEFChartWebView.java:84) at edu.vt.cs.collab.bridge.DefaultWebViewServlet.doGet(DefaultWebViewServlet.java:95) at edu.vt.cs.collab.cork.impl.servlet.CORKServlet.doGet(CORKServlet.java:293) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) ....
The offending code segment was:
img = new BufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_RGB); g = img.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, sz.width, sz.height); comp.setBounds(0, 0, sz.width, sz.height); comp.paint(g);
comp was a fairly uncomplicated Swing component. This turned out to be Sun bug 6189824. The work-around noted in the bug report, adding a call to:
seems to have fixed the problem.
For scripting or debugging it is sometimes useful to be able to launch WebStart from the command line, rather than from a web browser. “Launching Java WebStart from the Command Line” describes several options for doing this, along with examples for OSX, Linux, and Windows.
Every once in a while I run into a situation where the usual means for generating a thread dump does not work, making it difficult to track down pesky deadlocks. Rather than actually figuring out why that happens, here are some notes on using jdb to generate a stack trace: JDB Example: Generating a Thread Dump.
In searching for a Java library to parse RSS and Atom feeds I ran across FeedParser from the Apache Jakarta Project. From a few quick experiments this looks pretty slick, but is unfortunately marked as “dormant” and shows no evidence of having been updated in a few months.
Presumable as a side-effect of domancy, no archive of the library is availalable. The source can be checked out of the SVN repository, but the URL given on the “anonymous SVN access” page only allows browsing. After a bit of trial-and-error based on other (less dormant) Jakarta projects, the correct URL for grabbing the code with svn appears to be:
The complete checkout command is then:
svn checkout http://svn.apache.org/repos/asf/jakarta/commons/dormant/feedparser/trunk/ feedparser
(with no line breaks).
UPDATE: And, of course, within minutes of posting this I find the answer that escaped my earlier googling.
GridBagLayout is, at times, a little too flexible. This simple example illustrates the use of GridBagLayout to generate nicely aligned forms for entering data.
JProfiler is a great tool for tracking down pesky memory leaks and performance problems. Here’s a trick for configuring JProfiler for use with remote Java Web Start applications on OSX.
java.util.zip package includes classes for compressing and decompressing data using the ZLIB algorithms. The stream classes in the package are well-suited for accessing files and other bounded data, but do not work as well for compressing unbounded, continuous data transmitted over a socket. “Compressing data sent over a socket” describes the underlying issues and illustrates a pair of stream classes that can be used for compressed communication over a socket connection.
Apache’s Lucene text search library provides powerful and flexible tools for searching collections of text. While the indexes that Lucene builds are often stored on disk, the libary includes the ability to create an index in memory. This is particularly useful in restricted environments such as unsigned applets and WebStart applications. “Lucene In-Memory Text Search” shows a minimal example of creating and searching such an index.
Strings are Objects in Java, but the ability to use literals, along with the String concatenation operator, make them somewhat similar to primitive types. Java also automatically “interns” String literals, meaning that a single String object will be created for a literal that is used multiple times. “String Equality and Interning” describes the effect of interning on String equality testing using the
== operator and the