Skip to content

Instantly share code, notes, and snippets.

package utils;
import java.util.HashSet;
import java.util.Set;
public class KeyValue {
private static final char DELIMITER = ':';
private static final char KEY_VALUE_DELIMITER = ',';
private static final char ESCAPE_CHAR = '\\';
@aembleton
aembleton / build.xml
Created August 21, 2012 15:40
Ant script that packages up all of the jars into a single executable jar
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="jar">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="DataPersist.classpath">
<pathelement location="bin"/>
<pathelement location="lib/commons-cli-1.1.jar"/>
<pathelement location="lib/commons-io-1.2.jar"/>
@aembleton
aembleton / Bean.java
Created July 26, 2011 11:02
Auto-generated toString useful for all beans.
/*
Copyright (c) 2007 Arthur Embleton
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@aembleton
aembleton / MapUtil.java
Created July 26, 2011 10:49
Converts a List into a Map where the key is set to the value returned by calling the getter for the specified keyProperty on each element of the List and the value is set to the object held in the List.
package net.blerg.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@aembleton
aembleton / JsonUtil.java
Created July 22, 2011 08:23
Utility class containing static methods that are useful for reading in and marshalling JSON
package net.blerg.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
@aembleton
aembleton / MapToData.java
Created July 21, 2011 15:55
Converts a Map into URLEncoded data that can be used in a POST
package net.blerg;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@aembleton
aembleton / StringUtil.java
Created May 19, 2011 10:36
Useful String utility methods.
package utils;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
@aembleton
aembleton / Ignore certificate for HttpURLConnection in Android.java
Created March 27, 2011 17:25
The following code disables SSL certificate checking for any new instances of HttpsUrlConnection
/**
* Disables the SSL certificate checking for new instances of {@link HttpsURLConnection} This has been created to
* aid testing on a local box, not for use on production.
*/
private static void disableSSLCertificateChecking() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@aembleton
aembleton / Regex.java
Created March 17, 2011 23:39
Matches regular expressions in the haystack. Any matched strings are returned in a list.
package util;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
/**
@aembleton
aembleton / Only UK but this Perl can be expanded upon
Created March 15, 2011 14:56
Call Perl number normalisation from Java
#!/usr/bin/perl
use strict;
use warnings;
my $n = $ARGV[0];
my $country = $ARGV[1];
if ($country eq "GB") {
if ($n =~ /^0(\d{10})$/x) {