XStream Notes

Using xstream-1.4.2.jar, and got the following problem:

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
at com.thoughtworks.xstream.XStream.<init>(XStream.java:336)
at com.hempire.xstream.Writer.main(Writer.java:22)

The XML Pull Parser API defines an own mechanism to load the factory for the available XPP (XML Pull Parser) implementation. XStream's XppDriver never used this lookup mechanism automatically before version 1.4, now it will. Therefore you will have to add a dependency to xmlpull if the XPP implementation does not deliver the classes on its own. This dependency is necessary for Xpp3 in contrast to kXML2 that contains the classes. Use the Xpp3Driver or the KXml2Driver if you want to select one of the directly supported XPP implementation on your own without using the XPP factory. Note, that the minimal version of kXML2 does not support the XPP factory, but can be used by the KXml2Driver.

I honestly don't understand what the above means, but the bottom line is if we include any of the following jars, you should be fine:

kxml2-2.3.0.jar
kxml2-min-2.3.0.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar

kXML2 is recommend for use as it will greatly improve the performance of XStream.

Supported XML parsers and packages:

Get to Jira (or any web) quick from cygwin

1. Put the following in .bashrc:
export jira="https://jira.dovetail.net/browse/BUG-"
2. Make it effective:
source .bashrc
3. under /home/hliu/bin,  create file named as "jira":
cygstart "$jira$1"
4. Make it executable:
dos2unix jira
chmod 755 jira
5. Now from cygwin, you could type:

How to put codes nicely in Blog Using SyntaxHighlighter

Link

Change template is one time thing. After that, whenever you need put codes into blog, in HTML mode, put codes between

<pre class="brush:java"> ... </pre>

<script type="syntaxhighlighter" class="brush:xml">
</script>

You have the option to change the type of language, just as we are using java here, here is the list of the supported languages.

class='brush:java'
class='brush:as3'   //action script 3
class='brush:bash'
class='brush:css'
class='brush:groovy'
class='brush:js'    //java script
class='brush:py'
class='brush:sql'
class='brush:xml' //xml, xslt, html

My Template: add before </head>

Faster Copy Files

 
public static void copyFile(File sourceFile, File destFile) throws IOException 
{
  if (!destFile.exists()) 
  {
    destFile.createNewFile();
  }

  FileChannel source = null;
  FileChannel destination = null;
  try 
  {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    destination.transferFrom(source, 0, source.size());
  } 
  finally 
  {
    if (source != null) 
    {
      source.close();
    }
    if (destination != null) 
    {
      destination.close();
    }
  }
}
    
Link

XStream

http://xstream.codehaus.org/
http://www.ibm.com/developerworks/xml/library/x-xstream/
Library of serializing object to XML and deserializing object back from XML
1) Example of converting a list of object into a XML file:
public boolean XStream2XML(List importEntryList, String strOutXMLFilePath) 
{
  XStream xs = new XStream();

  //by default, xstream will use class's full name
  //you could use alias to avoid that
  xs.alias("entryList", List.class);
  xs.alias("importentry", ImportEntry.class);
  xs.alias("attribute", Attribute.class);

  try 
  {
    FileOutputStream fs = new FileOutputStream(strOutXMLFilePath);
    xs.toXML(importEntryList, fs);
    //a simpler version
    //String xml = xs.toXML(importEntryList);
    fs.close();
  } 
  catch (Exception e1) 
  {
    //e1.printStackTrace();
    return false;
  }

  return true;
}
2) Example of converting XML back to Java Object
String xml = "......";
Person newJoe = (Person)xstream.fromXML(xml);

Create Symbolic Link

ln -s source_file link_name

Java Preferences

Here is the situation, you want to save some user preferences, for example, I like certain columns for a given table, I don't want to customize it every time, I'd like to save it. Originally, I thought I might need a configuration file to achieve this, but soon I realize that it would be a pain, first of all, where to put this file? if my application is achieved, I don't even have the access the application folder. Secondly, every time I update the file, I need search this file and remove the old entry. I think there got to be a better way to do this.

Link
Link

In windows, it's stored under
HKEY_CURRENT_USER\Software\JavaSoft\Prefs

Just so we know, that we could import and export part of Registry, in this way, if we change our machine, we could just export/import and go.