Recent Notes
Displaying keyword search results 1 - 10
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 lokf on January 13, 2012 14:10:42
Last update: January 13, 2012 14:10:42
For some reason I don't know writing to files in Android is very complicated and tedious. Here is some code for those who might need it. Apps should write in the SD in the directory /Android/data/package_name/files/ so that it is deleted with the app uninstall. package randomname; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.ByteBuffer; import android.content.Context; import android.os.Environment; import android.util.Log; public class FileIOLibrary { String packageName; boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; FileIOLibrary(String packageNamep) { this.packageName=packageNamep; } public boolean isExternalStorageAvailable() { updateExternalStorageState(); return mExternalStorageAvailable; } public boolean isExternalStorageWritable() { updateExternalStorageState(); return mExternalStorageWriteable; } /** * writes the current state of SD card to the corresponding variables */ void updateExternalStorageState() {...
Created by Fang on November 21, 2011 15:57:49
Last update: November 22, 2011 09:51:26
The improved custom taglib works with existing facelet ui taglibs. For example:
<ui:param name="theName" value="John"/> <my:hel... produces the expected output. However, a problem exists with the ui:repeat tag: <h3>With ui:repeat</h3> <ui:repeat var="theName... When tested with a URL like: http://localhost:8080/facelet-demo/?name=Zack&name... the raw EL prints out the correct names, but my custom tag substitutes empty string for theName2 ! In theory, the response is rendered in the Render Response phase, way after the Apply Request Values phase, actual values should be available to EL. The answer to this anomaly turned out to be very deep ! Yes, right there in the code! I would consider this a bug in facelets implementation, but the JSF spec did not tell what the expected behavior should be. In my custom...
Created by freyo on May 13, 2011 15:45:29
Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator.
build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<man...
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<Lin...
res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<res...
src/com/android/xmltool/DumpXml.java
package com.android.xmltool;
import java.ut...
Screenshot
Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
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......
Created by Dr. Xi on June 21, 2011 15:41:51
Last update: June 22, 2011 11:33:36
Demo code for CSV parsing with Apache Commons CSV parser .
Java code:
import java.io.*;
import org.apache.commons.csv...
Test with a simple CSV file:
psmith01,CLASS2B,Peter Smith 1,YEAR2,1,N,ADVANCED,...
Result:
Line 1 has 11 values:
|psmith01|
|CLASS2B|...
The parser worked correctly.
Test with a more complicated CSV file:
"psmith01 abc", "CLASS2B " , " Peter...
Result:
Line 1 has 4 values:
|psmith01 abc|
|CLASS...
The third line is invalid input, but throwing a Java IOException is a bit grave. Also, the parser is not able to escape a backslash.
Add a new line in item two:
"One", "Two
", "Three"
Result:
Line 2 has 3 values:
|One|
|Two
|
|...
Created by Dr. Xi on June 21, 2011 15:54:00
Last update: June 22, 2011 11:33:09
Demo code for CSV parsing with SuperCSV parser .
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 5 values:
|psmith01 abc|
|CLASS...
Using two lines input:
"psmith01 abc", "CLASS2B " , " Peter...
It generates an exception:
Line 1 has 5 values:
|psmith01 abc|
|CLASS...
Add a new line in item two:
"One", "Two
", "Three"
Result:
Line 2 has 3 values:
|One|
|Two
|
|...
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 alfa on June 03, 2011 09:41:03
Last update: June 03, 2011 09:41:03
Dynamic proxy can be used to eliminate the need to stub out unused interface methods. This is an example for a simple SAX content handler for XML parsing.
The org.xml.sax.ContentHandler interface requires 11 methods be implemented but we only need three:
import java.io.IOException;
import java.util.Ar...
With a dynamic proxy, we don't need the empty blocks for the unused methods:
import java.io.IOException;
import java.util.Ar...
Equivalently (with anonymous inner class):
import java.io.IOException;
import java.util.Ar...
demo.xml :
<breakfast-menu>
<food>
<name>Belgian W...