Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on June 22, 2011 13:23:19
Last update: April 30, 2012 11:40:06
This is a utility to convert a byte array to hex string, and to convert a hex string back to the original.
To convert a String to hex, you must call String.getBytes() first. The utility does not pretend to know your string encoding.
public class StringHexUtil {
public static ...
This also works:
String binaryToHex(byte[] data) {
StringBui...
Created by Dr. Xi on March 08, 2012 12:13:57
Last update: March 08, 2012 12:13:57
This example creates an instance of XMLGregorianCalendar and converts it to java.util.Date :
import java.util.Date;
import javax.xml.datatyp...
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 Dr. Xi on February 07, 2012 15:40:11
Last update: February 07, 2012 15:40:11
An alias defined in .profile does not work when you open a bash window from the desktop. Simply put, alias should be put in .bashrc ; PATH should be put in .profile . These are the facts: .profile is executed by the login shell, i.e., when you login. .bashrc is executed whenever a bash shell is opened - login or non-login. When you open a new bash window from the desktop, a non-login shell is created, it will execute .bashrc , not .profile . When you ssh to a remote system interactively, a login shell is created. When you ssh to a remote system and run a command directly, a non-login shell is created. PATH modifications should be put in .profile since it is usually...
Created by Dr. Xi on February 06, 2012 09:20:20
Last update: February 06, 2012 09:20:20
This is the error message:
Error 6 initializing SQL*Plus
SP2-0667: Message...
It might be that the ORACLE_HOME environment variable is not properly set or a missing sp1<lang>.msb (for example sp1us.msb ) file. But for my Ubuntu system, there was no such thing as sp1<lang>.msb , and it wasn't caused by a missing ORACLE_HOME . The error was resolved after I restored the shared library file libsqlplusic.so .
Created by Dr. Xi on January 06, 2012 14:02:09
Last update: January 06, 2012 14:02:09
In Java, the OS temporary directory is identified by the system property java.io.tmpdir :
public class TmpDir {
public static void ma...
Created by Dr. Xi on November 11, 2011 13:59:46
Last update: November 11, 2011 13:59:46
This is an example to replace a Java string with case insensitive match.
Code:
public class ReplaceTest {
public static vo...
Output:
Done TEST tEst tESt Test
Test TEST tEst tESt Te...
Created by Dr. Xi on November 11, 2011 10:05:22
Last update: November 11, 2011 10:12:01
This is an HTML image tag filter using Java regex. It takes a string, finds the img tags, replaces the src attribute with one provided by the filter, then adds a class name to the class attribute.
import java.util.regex.*;
import java.io.*;
...
Test file:
<div id="HTML snippet">
<img src="img/big/txt-m...
Created by Dr. Xi on July 27, 2011 08:55:34
Last update: July 27, 2011 08:55:34
It is OK to remove elements from a list with Iterator , but you get UnsupportedOperationException if the list is created with Arrays.asList :
import java.util.*;
public class IteratorRe...
Prints:
ArrayList test:
================
List size: ...
Created by Dr. Xi on July 15, 2011 09:25:15
Last update: July 15, 2011 09:25:15
Some methods to search for a substring within a string:
To know that a substring indeed exists within a string:
boolean found = wholeString.contains(substring);
To find where the substring is contained:
int index = wholeString.indexOf(substring);
If the substring is regex:
boolean match = wholeString.matches(".*" + substri...
Case insensitive match: convert both whole string and substring to lowercase, then compare. Or, use case insensitive flag for regex.
Test code:
import java.util.regex.*;
public class Stri...