Recent Notes

Displaying keyword search results 31 - 40
Created by Dr. Xi on June 22, 2011 07:12:02    Last update: June 22, 2011 11:32:02
Demo code for CSV parsing with OstermillerUtils . Java code: import java.io.*; import java.util.List; imp... 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... The parser messed up on all three lines: Line 1 has 6 values: |psmith01 abc| | "CLA... Putting a space before the first quote: "Smith, Jack","210-345-8888" It dismissed the quotes: Line 1 has 3 values: | "Smith| | Jack"| ... Add a new line in item two: "One", "Two ", "Three" Result: Line 1 has 2 values: |One| | "Two| ...
Created by Dr. Xi on June 16, 2011 14:23:44    Last update: June 16, 2011 14:25:04
This example shows how a service implementation can be loaded with a URLClassLoader . The files. HelloService.java : public interface HelloService { public void... HelloServiceImpl.java : public class HelloServiceImpl implements HelloServ... ServiceFactory.java uses URLClassLoader to load the service implementation: import java.io.*; import java.net.*; pub... Test.java : import java.io.*; import java.net.*; pub... Create a runnable client jar: C:\>jar -cfe client.jar Test Test.class ServiceFac... Create a service jar: jar -cf service.jar HelloServiceImpl.class Test: C:\>java -jar client.jar Class Loader: java.net... Extra Note: : JDK7 added a method URLClassLoader.close() , so that a URLClassLoader can be discarded, and a new one created to load a new implementation.
Created by alfa on June 02, 2011 13:04:18    Last update: June 02, 2011 13:04:18
Some javap usage examples. Start from HelloWorld.java : @Deprecated public class HelloWorld { pu... javap -c HelloWorld outputs: Compiled from "HelloWorld.java" public class He... javap -v HelloWorld outputs ( -v for verbose mode): Compiled from "HelloWorld.java" public class He... The output consists of: " Compiled from... " header Class attributes. For the HelloWorld example, there are two: SourceFile and Deprecated . Minor and major class file version Constant pool Disassembled code LineNumberTable for debugging purposes. javap by default only prints package/protected/public members. To display all members including private, use the -p switch. javap -v -p HelloWorld
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 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...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by freyo on May 09, 2011 15:13:59    Last update: May 09, 2011 15:14:22
This code snippet opens and reads the Android APK archive file for a given package name. // import java.io.*; // import java.util.zip.*;...
Created by freyo on May 09, 2011 12:50:52    Last update: May 09, 2011 12:51:54
You can use the android.os.StatFs class to check for available space on the sd card. Example code: // import android.os.Environment; // import...
Created by freyo on May 09, 2011 11:55:27    Last update: May 09, 2011 11:55:27
Reading from or writing to sdcard isn't any different from normal Java io operations. Just use Java io to open the file then read from or write to it. Android does provide some utility methods to lookup directories under the sdcard. Examples: // import android.os.environment File extDi... Example logcat output: D/Test ( 1353): External storage dir from Envi... To write to sdcard: try { FileWriter out = new FileWriter(new F...
Previous  1 2 3 4 5 6 7 8 9 10 Next