Xr's blog

To content | To menu | To search

Tag - java

Entries feed

Monday, March 16 2009

Getting the JVM arguments from Java

While working on a Java software, I developed an utility that forked into background so that the VM could return instantly without using system-dependent tools like the shell or Debian's start-stop-daemon. My utility chose the right JVM (using the java.home system property) and started a new VM, calling the same main class with the same arguments, using the same classpath. Everything was fine.

However, when I came to using it on a somewhat more advanced setup, I came across a problem: JVM arguments weren't passed to the running VM. No memory configuration (-Xmx), no instrumentation (-agentlib)...

Continue reading...

Saturday, February 14 2009

Java, XML and indenting (continued)

This is a followup to Java, XML and indenting.

More fun in the "Why doesn't my XML source get indented" series.

When you build a StreamResult and you want indentation, instanciate it with a Writer. If you use a regular OutputStream (like System.out, for example), you will have new lines but no indentation.

Of course, it's not documented. The Javadoc for StreamResult(Writer) only says:

Construct a StreamResult from a character stream. Normally, a stream should be used rather than a reader, so that the transformer may use instructions contained in the transformation instructions to control the encoding. However, there are times when it is useful to write to a character stream, such as when using a StringWriter.

See those useful times ? I guess it's what they're talking about.

Thursday, January 22 2009

Programmatically using LimeWire for BitTorrent transfers

While working on a Java project (which doesn't have a real homepage yet) with a friend and colleague, we felt the need to provide an efficient way to transfer potentially massive files on a Peer-to-Peer computing network (as opposed to the well known P2P data networks). We agreed on the use of BitTorrent, for a bunch of technical reasons (for example, see [1], [2], [3], [4], ...)

After digging for a few days, the best solution I found was to use Azureus (now called Vuze). After a lot of work, I succeeded in using both the client and the tracker in a programmatic way. However, for reasons that I can't or don't want to explain without trolling, we were never really happy with it.

Not much later, LimeWire added support for BitTorrent. And this week, I finally got the time and motivation to look into it.

Continue reading...

Thursday, September 11 2008

Java, XML and indenting

A while ago, a friend/colleague was having trouble outputting formatted XML with Java's XML API. Both our codes output valid XML, but only mine was indenting it.

Basically, they looked like this (some logic skipped for ease of reading):

Continue reading...