Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on November 01, 2013 10:23:45    Last update: November 01, 2013 10:23:45
This example class generates and verifies RSA signature on a test file. import java.io.*; import java.security.*; im...
Created by Dr. Xi on October 31, 2013 18:17:09    Last update: October 31, 2013 18:17:09
You have a PGP public in PEM format, which cannot be stored in a Java key store. But you have the PEM encoded public key file. This class reads the file and creates a public key class in Java. Example key file: -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0B... Java code: import java.io.*; import java.security.*; im...
Created by Fang on October 10, 2013 12:48:19    Last update: October 10, 2013 12:48:19
Sample code to copy a file with Java nio. import java.io.*; import java.nio.channels.File...
Created by Fang on January 04, 2013 09:02:44    Last update: January 04, 2013 09:02:44
This snippet sets system properties from Maven surefire test plugin. This is useful when you want to set logging (for example, log4j) properties based on Maven project properties. Example that sets system property testlog.dir : <plugins> <plugin> <groupId>org.apach... Example log4j.xml that uses system property testlog.dir : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYP...
Created by Dr. Xi on May 02, 2011 15:59:37    Last update: February 25, 2012 09:16:37
This code snippet gets the default keystore used by the Java keytool and displays the list of aliases along with the key type (certificate or private key). import java.io.File; import java.io.FileInputSt... The default keystore used by the above code is: $HOME/.keystore .
Created by Dr. Xi on November 11, 2011 10:05:22    Last update: November 11, 2011 10:12:01
This is an HTML image tag filter using Java regex. It takes a string, finds the img tags, replaces the src attribute with one provided by the filter, then adds a class name to the class attribute. import java.util.regex.*; import java.io.*; ... Test file: <div id="HTML snippet"> <img src="img/big/txt-m...
Created by Fang on November 10, 2011 09:26:12    Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines! <?xml version="1.0" encoding="UTF-8"?> <xsd:sch...
Created by alfa on July 15, 2011 13:25:45    Last update: July 15, 2011 13:25:45
Read the whole contents of a file into a String. It's better to read the whole file as bytes and convert to String than to read the file line by line and concatenate the lines. String getFileContents(String fileName) throws... Using java.nio : import java.io.FileInputStream; import java...
Created by Dr. Xi on July 13, 2011 16:18:05    Last update: July 13, 2011 16:18:05
The goal is to read a file like this: for (String line: textFileReader) { // do s... This is the code: import java.io.*; import java.util.Iterator; ...
Created by Dr. Xi on June 22, 2011 07:33:45    Last update: June 22, 2011 11:57:54
Demo code for CSV parsing with OpenCSV . Java code: import java.io.*; import au.com.bytecode.opencs... Test with a simple CSV file: psmith01,CLASS2B,Peter Smith 1,YEAR2,1,N,ADVANCED,... The parser worked correctly: Line 1 has 11 values: |psmith01| |CLASS2B|... Test with a more complicated CSV file: "psmith01 abc", "CLASS2B " , " Peter... Result: Line 1 has 4 values: |psmith01 abc| |CLASS... The parser: Escaped quote and backslash correctly Ignored spaces before the quotation mark - sometimes (see below) Counted spaces after the right quotation mark till the comma as content, including the right quotation mark (bug). Ignored improperly quoted item - silently (third line) Indeed, the OpenCSV parser has a problem with spaces: Input: "Smith, Jack", "210-345-8888" "Smith, J... Result: Line 1 has 2 values: | Smith, Jack| |210-3......
Previous  1 2 3 4 5 6 Next