Displaying keyword search results 101 - 110
Created by alfa on May 25, 2011 20:56:16 Last update: May 25, 2011 20:57:31
The general construct of a non-capturing group is: (?:X) , i.e., add ?: after the opening bracket of an otherwise capturing group. Example code:
import java.util.regex.*; public class NonC...Output:
Matched: a capturing Subgroup 1: a Subgroup ...
Created by alfa on May 25, 2011 20:17:52 Last update: May 25, 2011 20:39:35
In Java regex, by default, the dot character does not match the newline character ( \n ). It matches a newline character only when the DOTALL flag is set. Example:
import java.util.regex.*; public class Dota...
Created by alfa on May 25, 2011 20:08:21 Last update: May 25, 2011 20:08:21
In MULTILINE mode, ^ matches the begging of the string as well as the beginning of a new line; $ matches the end-of-string as well as the newline character. In normal (non- MULTILINE mode), ^ only matches the begging of the string; $ only matches the end-of-string. Example:
import java.util.regex.*; public class ...
Created by alfa on May 25, 2011 15:22:08 Last update: May 25, 2011 15:25:05
Use Matcher.find() to find the next regex match until all matches are exhausted.
import java.util.regex.*; public class RegE...To get case insensitive match, use:
Pattern p = Pattern.compile("(?i)\\b(m|c)\\w*(n|r|...
Created by alfa on May 24, 2011 15:59:41 Last update: May 24, 2011 15:59:41
Java reflection with Apache beanutils example.
import org.apache.commons.beanutils.MethodUtils; ...
Created by freyo on May 24, 2011 09:15:14 Last update: May 24, 2011 09:15:14
Java built-in X.509 certificate factory reads CertPath objects encoded in PkiPath or PKCS7 formats. The META-INF/<key_alias>.RSA file generated by Java jarsigner is in PKCS7 format. Example code:
import java.util.*; import java.io.*; import...PKCS7 files can also be generated by openssl from certificate file(s):
openssl crl2pkcs7 -nocrl -certfile Certs.pem -out ...Convert PKCS7 from DER to PEM:
openssl pkcs7 -in certs.pk7 -inform DER -out certs...Sample PKCS7 file:
-----BEGIN PKCS7----- MIIERwYJKoZIhvcNAQcCoIIEO...
Created by freyo on May 23, 2011 14:30:18 Last update: May 23, 2011 14:31:08
There are two distinct ways to process XPath: with namespace and without namespace. The code is different depending on whether the parser is namespace aware. Code without namespace:
import java.io.*; import javax.xml.parsers.*; ...code with namespace:
import java.io.*; import java.util.Iterator; ...XML without namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...XML with namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...The same XPath expression works for both XML files when the parser is not namespace aware. When the parser is namespace aware, you have to adjust the XPath accordingly depending on whether the XML has namespace declarations: " /test-license/licensee/name/text() " works for the XML file without namespace, while " /p:test-license/p:licensee/p:name/text() " works for the XML file with namespace.
Created by freyo on May 20, 2011 09:25:20 Last update: May 23, 2011 12:11:42
The javax.xml.crypto and javax.xml.crypto.dsig packages are not available in Android (as of version 2.3). Therefore, standard Java API does not work. But you can use the Apache Santuario library to do that. Here are the steps: Download the xml security source distribution (curently version 1.4.4). Build with ant. Create your own library jar (only the apache classes, no javax):
jar -cf xmlsec-1.4.4.jar -C build/classes orgCopy xmlsec-1.4.4.jar to the libs directory of your Android project. Here's the Java code:
import java.io.*; import javax.xml.parsers.*; ...
Created by freyo on May 23, 2011 12:07:59 Last update: May 23, 2011 12:09:42
You can construct a java.security.cert.Certificate object from a string or byte array. Byte array is cleaner because for string you also have to know the character encoding.
// import java.security.cert.CertificateFactory; ...If the certificate string is encoded in "UTF-8", the ByteArrayInputStream should be created with:
Created by Dr. Xi on May 17, 2011 21:14:58 Last update: May 17, 2011 21:17:58
Read certificate one at a time from BufferedInputStream :
// import java.security.cert.*; public void rea...Read all certificates from a file as a collection:
public void readCertificates(File f) throws Except...