Here’s how to convert a Java string containing XML into a Document and back using only Java 1.5 built-in classes.
Here’s how to do a simple XSLT transformation using only classes in vanilla Java 1.5 (maybe even 1.4?), no external libraries or anything. The classes are found in the javax.xml.transform package.
TransformerFactory tf = TransformerFactory.newInstance();
throw new RuntimeException("Did not find a SAX-compatible TransformerFactory.");
SAXTransformerFactory stf = (SAXTransformerFactory) tf;
// Create a reusable template for the XSLT
Templates xslt = stf.newTemplates(new SourceStream(inputStreamWithXslt));
// Use the template to transform some XML
Needed something to generate random passwords and found Java Password Generator. It generates passwords which are gibberish, but still sort of readable, which I think is a lot nicer than pure gibberish.
I just wanted a simple ‘get me a new random password method’ though, and not all the applet and ‘make several passwords’ stuff. Decided to extract the useful parts and clean it up a bit. In case I need it again, or others need it, and since he states “share your source with others freely”, here is the result 🙂
Wanted to create an easy interface for reading lines from a stream. It should take care of all the annoying Java IO nitty-gritty for me and I wanted to use it simply by throwing it into a for loop.
Ok, so I was happily reading CSV files from an SFTP server. The file content is returned as an InputStream and I I used a BufferedReader to read it line by line. Each line contained either a header or an order. The header lines started with the string “HDR”.
However, I suddenly discovered that my code was consistently skipping the first header (and as a result the orders belonging to it). The reason, I found, was simple. The first header, on the first line, didn’t start with “HDR”, it started with “â–¡HDR”! And that undisplayable square turned out to be a Unicode Byte Order Mark (BOM).
To set the
JAVA_HOME environment variable you first need to find where your Java installation is located and then set it somehow.