Recent Notes

Displaying keyword search results 51 - 60
Created by nogeek on April 07, 2011 21:30:54    Last update: April 07, 2011 21:30:54
This is the opposite of parsing. You can use javax.xml.transform.Transformer to output a DOM tree to a file. import java.io.*; import javax.xml.parsers.Docu...
Created by nogeek on April 07, 2011 20:54:17    Last update: April 07, 2011 20:54:17
Use javax.xml.parsers.DocumentBuilder to parse xml. DocumentBuilder.parse() takes: java.io.File org.xml.sax.InputSource java.io.InputStream java.lang.String as a URI to an XML document Example code: import java.io.*; import javax.xml.parsers.Docu...
Created by freyo on April 07, 2011 15:29:01    Last update: April 07, 2011 15:29:01
Format Name Description PKCS #7 Cryptographic Message Syntax Standard A PKCS #7 file can be used to store certificates, which is a SignedData structure without data (just the certificates). The file name extension is usually .p7b , .p7c PKCS #8 Private-Key Information Syntax Standard. Used to carry private certificate keypairs (encrypted or unencrypted). PKCS #12 Personal Information Exchange Syntax Standard. Defines a file format commonly used to store private keys with accompanying public key certificates, protected with a password-based symmetric key. It is the successor to PFX from Microsoft. DER Distinguished Encoding Rules A binary format for keys or certificates. It is a message transfer syntax specified by the ITU in X.690. PEM Privacy Enhanced Mail Base64 encoded DER certificates or keys, with additional header...
Created by alfa on April 06, 2011 13:23:40    Last update: April 06, 2011 13:23:40
A file can be read as URL with the java.net package. You must provide absolute path after the URI scheme name file:// . package com.demo.io; import java.io.*; i...
Created by alfa on April 06, 2011 12:48:44    Last update: April 06, 2011 12:48:44
package com.demo.io; import java.io.*; ...
Created by alfa on April 06, 2011 12:07:12    Last update: April 06, 2011 12:08:01
You can use Class.getresourceAsStream or ClassLoader.getresourceAsStream to read a file from classpath. Class.getresourceAsStream delegates to ClassLoader.getresourceAsStream , but it does some preprocessing before delegation: If the file name begins with a '/', then the absolute name of the resource is the portion of the name following the '/'. Otherwise, the absolute name is: package_name_with_dot_replaced_by_slash/file_name package com.demo.io; import java.io.*; ...
Created by Dr. Xi on March 31, 2011 15:03:26    Last update: April 01, 2011 12:34:50
Create an openssl configuration file which enables subject alternative names ( openssl.cnf ): [req] distinguished_name = req_distinguished_... Create a certificate request using above configuration file: C:\work>openssl req -new -key testServer.key -out ... Verify the request was created successfully: C:\work>openssl req -text -noout -in testServer.cs... (Optional) self-sign the certificate request: C:\work>openssl x509 -req -days 3650 -in testServe...
Created by Dr. Xi on March 29, 2011 16:06:57    Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed. import java.io.InputStream; import java.io.Outp... Retrieve and import the a certificate: E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by Dr. Xi on January 14, 2010 00:28:27    Last update: March 30, 2011 15:37:44
A task that a Java developer does so frequently is to find out where a certain class can be found - to resolve compilation errors, classpath issues, or version conflicts of the same class introduced by multiple class loaders. A long while back I wrote a simple Perl script to perform the task. Later I was informed that there are Swing based Jar Browser and Jars Browser . Then, there are a couple of shell one-liners: # one liner 1 find -name "*.jar" -print0 | xarg... But all of them share the same problem: if a class is in a jar nested in another jar, it cannot be found. Such is the case for a class inside a jar under the WEB-INF/lib directory of a...
Created by Dr. Xi on March 30, 2011 13:43:05    Last update: March 30, 2011 13:45:27
Method 1 - use javap with verbose flag: $ javap HelloWorld -verbose | head Compiled fro... Method 2 - use a utility class: import java.io.*; import java.nio.ByteBuffer; ... According to the VM Spec , a Java class file has this structure: ClassFile { u4 magic; ...
Previous  2 3 4 5 6 7 8 9 10 11 Next