maandag 21 april 2014

Reading CSV files in bash script

idrolestartstophostvmnr
1role01nonovmhost2011
2role02nonovmhost2012
3role03yesnovmhost2013
4role04yesnovmhost2014
5role05yesnovmhost1511
6role06yesnovmhost1512
7role07yesnovmhost1513
8role08yesnovmhost1514
9role09yesnovmhost921
10role10yesnovmhost932
11role11noyesvmhost943
12role12noyesvmhost954
# hLookupHeaderIndex1
echo "(hLookupHeaderIndex1 id)    :"$(hLookupHeaderIndex1 id)
echo "(hLookupHeaderIndex1 start) :"$(hLookupHeaderIndex1 start)
echo "(hLookupHeaderIndex1 vmnr)  :"$(hLookupHeaderIndex1 vmnr)
# OUTPUT:
#(hLookupHeaderIndex1 id)    :1
#(hLookupHeaderIndex1 start) :3
#(hLookupHeaderIndex1 vmnr)  :6
# vLookup
echo "(vLookup start yes role)    :"$(vLookup start yes role)
echo "(vLookup stop yes role)     :"$(vLookup stop  yes role)
# OUTPUT:
#(vLookup start yes role)    :role03 role04 role05 role06 role07 role08 role09 role10
#(vLookup stop yes role)     :role11 role12
# sortByTwoColumns
ROLES=$(vLookup start yes role)
echo "(vLookup start yes role)                :"$ROLES
echo "(sortByTwoColumns vmnr host role ROLES) :"$(sortByTwoColumns vmnr host role $ROLES)
echo "(sortByTwoColumns host vmnr role ROLES) :"$(sortByTwoColumns host vmnr role $ROLES)
# OUTPUT:
#(vLookup start yes role)                :role03 role04 role05 role06 role07 role08 role09 role10
#(sortByTwoColumns vmnr host role ROLES) :role05 role09 role06 role10 role07 role03 role08 role04
#(sortByTwoColumns host vmnr role ROLES) :role05 role06 role07 role08 role03 role04 role09 role10
# vOptions
echo "(vOptions start)   :"$(vOptions start)
echo "(vOptions host)    :"$(vOptions host)
# OUTPUT:
#(vOptions start)   :no yes
#(vOptions host)    :vmhost151 vmhost201 vmhost92 vmhost93 vmhost94 vmhost95
#!/bin/sh 
function checkCSVTableExists() {
 if [[ -z $CSV_FILE ]] ; then
  echo "$0 Error: export CSV_FILE=./config/config.template.csv $CSV_FILE"
  exit 5
 fi
 if [[ ! -f $CSV_FILE ]] ; then
  echo "$0 Error:CSV_FILE does not exist with name: $CSV_FILE "
  exit 10
 fi
}
# Controleer of de CSV_FILE is gezet, anders stoppen
checkCSVTableExists
# hLookupHeaderIndex1(name)
#
# lookup the index value, starting with 1 for the first column.
# Arg1 String Name of the column
# return int index of column
# Example :$(hLookupHeaderIndex1 'testsoort') 
function hLookupHeaderIndex1() {
 NAME=$1
 # tolowercase
 HEADER=$(head -n1 ${CSV_FILE})
 HEADER=$(tr [A-Z] [a-z] <<< "$HEADER")
 NAME=$(tr [A-Z] [a-z] <<< "$NAME")
 # Check if name in Header
 if [[ $HEADER != *$NAME* ]] ; then
  echo "$0 Error 1001 hLookupHeaderIndex1 not found:  NAME= $NAME HEADER= $HEADER"
  exit 1001
 fi
 PINDEX=$(echo ";"$HEADER";"|sed "s/;$NAME;.*//g"|tr ';' '\n' |wc -l )
 echo $PINDEX;
 return 0
}
# vLookup(column match column)
# lookup matching rows and return values.
# arg1 String headername
# arg2 String match
# arg3 String return column
# return String values in matching column
# Example :$(vLookup  'role' 'role11' 'host')
function vLookup() {
 ColumnIdx=$(hLookupHeaderIndex1 $1 )
 MATCH=$2
 PINDEX=$(hLookupHeaderIndex1 $3 )

 while read LINE ; do
  VALUE=$(echo $LINE | cut -d';' -f$ColumnIdx )
  if [[ $MATCH == $VALUE ]] ; then 
    echo $LINE | cut -d';' -f$PINDEX
  fi
 done < $CSV_FILE
}
# sortByTwoColumns(column1 column2 column_match match_values ..)
#
# arg1 String sort Column name one
# arg2 String sort Column name two
# arg3 String Column name match value
# arg4-n String match values in sorted order
#
function sortByTwoColumns() {
  Column1=$(hLookupHeaderIndex1 $1);shift
  Column2=$(hLookupHeaderIndex1 $1);shift
  Column3=$(hLookupHeaderIndex1 $1);shift
  AWK='{ print $'$Column1'";"$'$Column2'";"$'$Column3'}' # build AWK statement
  GREP=';'$(echo ""$@""|sed 's/ /$|;/g')'$'              # build GREP filter
  tail -n+2 $CSV_FILE|awk -F';' "$AWK"|grep -E $GREP|sort|cut -d';' -f3
}
# vOptions(column)
# arg1 String column name
# return choicelist from the specified column
function vOptions() {
 PINDEX=$(hLookupHeaderIndex1 "$1")
 # skip first line tail -n +2 (start linenumber)
 LIST=$(tail -n +2 $CSV_FILE| cut -d';' -f${PINDEX}|sort|uniq)
 echo $LIST
}

donderdag 23 januari 2014

Calculate Time in bash

#!/bin/sh
# +0:00 or +00:00 or -0:00 or -00:00
# returns seconds as int
function getSeconds() {
 SIGN=$(echo $1|cut -c1)"1"
 HOUR=$(echo $1|cut -d':' -f1|cut -c2- )
 HOUR=$(echo "${HOUR#0}")
 MIN=$(echo $1|cut -d':' -f2)
 MIN=$(echo "${MIN#0}")
 SECONDS=$(((HOUR * 3600) + (MIN * 60)))
 echo $((SECONDS * SIGN))
}

# seconds as int -10, 0 or 70
# returns +0:00 or +23:00 or -1:00 or -11:00
function formatSecondsToTime() {
 dt=$1
 SIGN="+"
 if [[ $1 -lt 0 ]] ; then
  SIGN=$(echo $1|cut -c1)
  dt=$(echo $1|cut -c2-)
 fi
 dm=$(((dt / 60  ) % 60))
 dh=$(((dt / 3600) % 24))
 VALUE=$(printf '%d:%02d' $dh $dm)
 echo $SIGN$VALUE
}

function addMinutes(){
 SEC1=$(getSeconds $1)
 SEC2=$(getSeconds $2)
 CALC=$((SEC1 + SEC2 ))
 #echo "$1 $2 $SEC1 + $SEC2 = $CALC formatted= $(formatSecondsToTime $CALC)"
 echo $(formatSecondsToTime $CALC)
}
function printTime() {
 SECONDS=$(getSeconds $1)
 echo "$1 $SECONDS $(formatSecondsToTime $SECONDS)"
 #echo "$1 $SECONDS $(formatSecondsToTime $SECONDS) $(getSign $1) $(getHours $1) $(getMinutes $1)"
}

# test
printTime "+00:01"
printTime "-00:10"
printTime "+01:00"
printTime "+09:10"
printTime "+09:01"
printTime "-11:10"
printTime "-09:59"
printTime "-23:59"
printTime "-10:59"
printTime "-000:059"
printTime "-25:89"
printTime "-24:61"
printTime "-24:00"
Output:
+00:01 60 +0:01
-00:10 -600 -0:10
+01:00 3600 +1:00
+09:10 33000 +9:10
+09:01 32460 +9:01
-11:10 -40200 -11:10
-09:59 -35940 -9:59
-23:59 -86340 -23:59
-10:59 -39540 -10:59
-000:059 -3540 -0:59
-25:89 -95340 -2:29
-24:61 -90060 -1:01
-24:00 -86400 -0:00
time="+01:22"
echo $(addMinutes $time "+0:01")
echo $(addMinutes $time "-0:01")
echo $(addMinutes $time "+1:01")
echo $(addMinutes $time "-1:01")
echo $(addMinutes $time "+24:01")
echo $(addMinutes $time "-24:01")
Output:
+1:23
+1:21
+2:23
+0:21
+1:23
-22:39

zaterdag 21 december 2013

Dynamically load jar file in systemclassloader

This example is showing how to download a jar file into the jvm and use the classes in that jar file. First we create a jar file with a Hello.class in it. The Hello.class does some logging when its get called. After creating the jar file we set up a HTTP server which alows us to download the jar file from a url. The next step is creating a Jython application which after is start will download the jar, put in into the system class loader and run the Hello.class. 1) Creating the Hello.class. This is a very basic class, which is printing if a method is called.
package nl.sysgarden;

public class Hello {
 public Hello() {
  System.out.println("Hello.function.Constuctor");
 }
 public static void main (String[] args){
  System.out.println("Hello.function.main");
 }
 public void p1(){
  System.out.println("Hello.funtion.p1");
 }
}
2) Creating a jar file: After compile 'javac nl/sysgarden/Hello.java' we put the class in the jar file httpjartest.jar
user$ jar cvf httpjartest.jar nl/sysgarden/Hello.*
added manifest
adding: nl/sysgarden/Hello.class(in = 540) (out= 343)(deflated 36%)
adding: nl/sysgarden/Hello.java(in = 272) (out= 146)(deflated 46%)
Testing the jar file bij calling the Hello class main function
user$ java -cp httpjartest.jar nl.sysgarden.Hello
Hello.function.main
3) Putting up the http deamon. Go to the directory where the jarfile is and activate the python webserver.
python -m SimpleHTTPServer 8080
Now we can download the jar file bij it's url http://localhost:8080/httpjartest.jar Next and final is creating the Jython app that starts and dynamicly adds the httpjartest.jar file to the systemclassloader.
$ cat classloaderExample.py 
import java.lang.System
import java.net.URLClassLoader
import java.net.URL

def printObject(obj):
 print 'obj:' + str(obj) 
 print 'cls:' + str(obj.getClass().getName())
 
def addJarToClassLoader(u):
        sysloader = java.lang.ClassLoader.getSystemClassLoader()
        sysclass = sysloader.getClass()
        #print str(sysclass.getDeclaredMethods())
        method = sysclass.getDeclaredMethod("addAppURL", [java.net.URL])
        print 'method= ' + str(method)
        method.setAccessible(1)
        jar_a = java.net.URL(u)
        b = method.invoke(sysloader, [jar_a])
        return sysloader

print 'step 1 download jar file and add it to the systemclass loader' 
sysloader = addJarToClassLoader('http://localhost:8080/httpjartest.jar' )
import nl.sysgarden.Hello
print 'step 2 create Hello object and print output' 
a=nl.sysgarden.Hello()
a.p1()
printObject(a)
Running the classloaderExample.py file
bash-3.2$ java -jar jython-standalone-2.5.3.jar classloaderExample.py 
step 1 download jar file and add it to the systemclass loader
method= void sun.misc.Launcher$AppClassLoader.addAppURL(java.net.URL)
step 2 create Hello object and print output
Hello.function.Constuctor
Hello.funtion.p1
obj:nl.sysgarden.Hello@6da05bdb
cls:nl.sysgarden.Hello

zondag 6 oktober 2013

Soapui groovy date formats

Soapui groovy date formats

Here are some examples of formating dates in soapui using groovy script.
Today is 6 october 2013, time 10:49 which can be expressed in iso 8601 'yyyy-mm-ddThh:mm:ss' 2013-10-06T22:49:50 as a local time in Amsterdam. Adding the timezone 2013-10-06T22:49:50+02:00 is the same as time as 2013-10-06T20:49:50Z. For more details see http://en.wikipedia.org/wiki/ISO_8601
// UTC
// 
// If the time is in UTC, add a Z directly after the time without a space.
// Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore 
// represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".
//
// UTC time is also known as 'Zulu' time, since 'Zulu' is the NATO phonetic alphabet
// word for 'Z'.
//
// Time offsets from UTC
//
// The following times all refer to the same moment: "18:30Z", "22:30+04", "1130-0700",
// and "15:00-03:30". Nautical time zone letters are not used with the exception of Z. 
// To calculate UTC time one has to subtract the offset from the local time, e.g. 
// for "15:00-03:30" do 15:00 − (−03:30) to get 18:30 UTC.
//
// An offset of zero, in addition to having the special representation "Z", can also
// be stated numerically as "+00:00", "+0000", or "+00". However, it is not permitted 
// to state it numerically with a negative sign, as "-00:00", "-0000", or "-00".

Default date formatting in Java Groovy

The Calendar class can be used for dates in groovy and Soapui.
For formatting it uses the java.util.SimpleDateFormatter.
The example uses different timezones and prints the value of the date.
import java.util.Calendar
import java.util.TimeZone

def printDate(zone){
 Calendar cal = Calendar.getInstance(zone);
 log.info "TimeZone               =" + cal.getTimeZone().getID()
 log.info "yyyy-MM-dd'T'HH:mm:ss  =" + cal.format("yyyy-MM-dd'T'HH:mm:ss")
 log.info "yyyy-MM-dd'T'HH:mm:ssz =" + cal.format("yyyy-MM-dd'T'HH:mm:ssz")
 log.info "yyyy-MM-dd'T'HH:mm:ssZ =" + cal.format("yyyy-MM-dd'T'HH:mm:ssZ")
 }

printDate( TimeZone.getTimeZone('GMT'))
printDate( TimeZone.getTimeZone('UTC'))
printDate( TimeZone.getDefault())
Output:
INFO:TimeZone               =GMT
INFO:yyyy-MM-dd'T'HH:mm:ss  =2013-10-06T20:49:50
INFO:yyyy-MM-dd'T'HH:mm:ssz =2013-10-06T20:49:50GMT
INFO:yyyy-MM-dd'T'HH:mm:ssZ =2013-10-06T20:49:50+0000
INFO:TimeZone               =UTC
INFO:yyyy-MM-dd'T'HH:mm:ss  =2013-10-06T20:49:50
INFO:yyyy-MM-dd'T'HH:mm:ssz =2013-10-06T20:49:50UTC
INFO:yyyy-MM-dd'T'HH:mm:ssZ =2013-10-06T20:49:50+0000
INFO:TimeZone               =Europe/Amsterdam
INFO:yyyy-MM-dd'T'HH:mm:ss  =2013-10-06T22:49:50
INFO:yyyy-MM-dd'T'HH:mm:ssz =2013-10-06T22:49:50CEST
INFO:yyyy-MM-dd'T'HH:mm:ssZ =2013-10-06T22:49:50+0200

Date format Zulu time in Java Groovy

Common use is a Zulu time format 2013-10-06T20:49:50Z as mentioned above. To use this format set the TimeZone to Zulu and format the date.
import java.util.Calendar
import java.util.TimeZone

def printDate(zone){
 Calendar cal = Calendar.getInstance(zone);
 log.info "yyyy-MM-dd'T'HH:mm:ss  =" + cal.format("yyyy-MM-dd'T'HH:mm:ssZ")
 cal.setTimeZone(TimeZone.getTimeZone('Zulu'))
 log.info "yyyy-MM-dd'T'HH:mm:ss'Z' =" + cal.format("yyyy-MM-dd'T'HH:mm:ss'Z'")
}
printDate( TimeZone.getDefault())
Output:
INFO:yyyy-MM-dd'T'HH:mm:ss    =2013-10-07T20:44:27+0200
INFO:yyyy-MM-dd'T'HH:mm:ss'Z' =2013-10-07T18:44:27Z

XML datetype

The XML datatypes uses a colon in the timezone +0200 is used as +02:00.
Which is both permitted in ISO 8601.
// http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes
// 3.2.7.1 Lexical representation
// The lexical representation of a timezone is a string of 
// the form: (('+' | '-') hh ':' mm) | 'Z', where
// '.' s+ (if present) represents the fractional seconds;
// zzzzzz (if present) represents the timezone (as described below).
// For example, 2002-10-10T12:00:00-05:00 (noon on 10 October 2002,
// Central Daylight Savings Time as well as Eastern Standard Time
// in the U.S.) is 2002-10-10T17:00:00Z, five hours later 
// than 2002-10-10T12:00:00Z. 
The java.util.SimpleDateFormatter class does not support ( untill java 7) the extra ':' in the timezone. A workaround would be to add the extra ':'.
 log.info "yyyy-MM-dd'T'HH:mm:ssZ =" + cal.format("yyyy-MM-dd'T'HH:mm:ssZ")
 StringBuffer offset = new StringBuffer(cal.format("Z"))
 offset.insert(3, ':')
 log.info "yyyy-MM-dd'T'HH:MM:ss  =" + cal.format("yyyy-MM-dd'T'HH:MM:ss") +offset
Output:
INFO:yyyy-MM-dd'T'HH:mm:ssZ =2013-10-07T20:44:27+0200
INFO:yyyy-MM-dd'T'HH:mm:ss  =2013-10-07T20:44:27+02:00

Diferrent formatting depending on your java version

Through time the SimplDateFormatter had some modification on the timezone Flag. The 'Z' was not supported in java < 1.4 SimpleDateFormat 1.3
z time zone (Text) Pacific Standard Time
Since java 1.4 'Z' is supported SimpleDateFormat 1.4 SimpleDateFormat 1.5 SimpleDateFormat 6
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
In java 7 xhe 'X' is added which should format the timezone as +08:00 SimpleDateFormat 7
z  Time zone General  time zone Pacific Standard Time; PST; GMT-08:00
Z  Time zone RFC 822  time zone -0800
X  Time zone ISO 8601 time zone -08; -0800; -08:00

Marshalling a java.util.Date object to a XML String

The next example of formating dates is to see how a java.util.Date object is formatted when serialized to xml. To do this we use the Marshalling class and write a date object to a XMLString.
import java.io.StringWriter
import java.util.Date
import javax.xml.bind.JAXBElement
import javax.xml.bind.Marshaller
import javax.xml.bind.JAXBContext
import javax.xml.namespace.QName

StringWriter writer = new StringWriter();
JAXBContext jc = JAXBContext.newInstance();
Marshaller m = jc.createMarshaller();
Date   value1 = new Date()
JAXBElement jx = new JAXBElement(new QName("date_example"), value1.getClass(), value1);
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(jx, writer);
log.info '' + writer
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<date_example>2013-10-06T23:14:34.058+02:00</date_example>
The implementation of the date to XML parsing can be found in the class: com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl RuntimeBuiltinLeafInfoImpl
// code duplicated from JAXP RI 1.3. See 6277586
private String format( String format, XMLGregorianCalendar value ) {
    StringBuilder buf = new StringBuilder();
    int fidx=0,flen=format.length();
    while(fidx < flen) {
        char fch = format.charAt(fidx++);
        if(fch!='%') {// not a meta char
            buf.append(fch);
            continue;
        }
        switch(format.charAt(fidx++)) {
        case 'Y':
            printNumber(buf,value.getEonAndYear(), 4);
            break;
        case 'M':
            printNumber(buf,value.getMonth(),2);
            break;
        case 'D':
            printNumber(buf,value.getDay(),2);
            break;
        case 'h':
            printNumber(buf,value.getHour(),2);
            break;
        case 'm':
            printNumber(buf,value.getMinute(),2);
            break;
        case 's':
            printNumber(buf, value.getSecond(),2);
            if (value.getFractionalSecond() != null) {
                String frac = value.getFractionalSecond().toPlainString();
                //skip leading zero.
                buf.append(frac.substring(1, frac.length()));
            }
            break;
        case 'z':
            int offset = value.getTimezone();
            if(offset == 0) {
                buf.append('Z');
            } else if (offset != DatatypeConstants.FIELD_UNDEFINED) {
                if(offset<0) {
                    buf.append('-');
                    offset *= -1;
                } else {
                    buf.append('+');
                }
                printNumber(buf,offset/60,2);
                buf.append(':');
                printNumber(buf,offset%60,2);
            }
            break;
        default:
            throw new InternalError();  // impossible
        }
    }
    return buf.toString();
}
Putting all together:
import java.util.Calendar
import java.util.Date
import java.util.TimeZone

def printDate(cal, zone){
 cal.setTimeZone(zone)
 log.info 'java.version = ' + System.getProperty("java.version")
 log.info "TimeZone     =" + cal.getTimeZone().getID()
 log.info "yyyy-MM-dd'T'HH:mm:ss        =" + cal.format("yyyy-MM-dd'T'HH:mm:ss")
 log.info "yyyy-MM-dd'T'HH:mm:ssz       =" + cal.format("yyyy-MM-dd'T'HH:mm:ssz")
 log.info "yyyy-MM-dd'T'HH:mm:sszz      =" + cal.format("yyyy-MM-dd'T'HH:mm:sszz")
 log.info "yyyy-MM-dd'T'HH:mm:sszzzz    =" + cal.format("yyyy-MM-dd'T'HH:mm:sszzzz")
 log.info "yyyy-MM-dd'T'HH:mm:ssX       =" + cal.format("yyyy-MM-dd'T'HH:mm:ssX")
 log.info "yyyy-MM-dd'T'HH:mm:ssXX      =" + cal.format("yyyy-MM-dd'T'HH:mm:ssXX")
 log.info "yyyy-MM-dd'T'HH:mm:ssXXX     =" + cal.format("yyyy-MM-dd'T'HH:mm:ssXXX")
 log.info "yyyy-MM-dd'T'HH:mm:ssZ       =" + cal.format("yyyy-MM-dd'T'HH:mm:ssZ")
 log.info "yyyy-MM-dd'T'HH:mm:ssZZ      =" + cal.format("yyyy-MM-dd'T'HH:mm:ssZZ")
 log.info "EEE, dd MMM yyyy HH:mm:ss Z  =" + cal.format("EEE, dd MMM yyyy HH:mm:ss Z")
 // log.info "Z=" + cal.format("Z")
 StringBuffer offset = new StringBuffer(cal.format("Z"))
 offset.insert(3, ':')
 // log.info "offset=" + offset
 log.info "yyyy-MM-dd'T'HH:mm:ss+offset =" + cal.format("yyyy-MM-dd'T'HH:mm:ss") +offset
 tz = cal.getTimeZone();
 cal.setTimeZone(TimeZone.getTimeZone('Zulu'))
 log.info "yyyy-MM-dd'T'HH:mm:ss'Z'     =" + cal.format("yyyy-MM-dd'T'HH:mm:ss'Z'")
 cal.setTimeZone(tz)
}
Calendar cal = Calendar.getInstance();

printDate(cal, TimeZone.getTimeZone('UTC'))
printDate(cal, TimeZone.getTimeZone('America/New_York'))
printDate(cal, TimeZone.getDefault())
log.info 'Wintertime'
cal.add( Calendar.MONTH, 2)
printDate(cal, TimeZone.getDefault())
Output:
INFO:java.version = 1.7.0_15
INFO:TimeZone     =UTC
INFO:yyyy-MM-dd'T'HH:mm:ss        =2013-10-07T21:35:30
INFO:yyyy-MM-dd'T'HH:mm:ssz       =2013-10-07T21:35:30UTC
INFO:yyyy-MM-dd'T'HH:mm:sszz      =2013-10-07T21:35:30UTC
INFO:yyyy-MM-dd'T'HH:mm:sszzzz    =2013-10-07T21:35:30Coordinated Universal Time
INFO:yyyy-MM-dd'T'HH:mm:ssX       =2013-10-07T21:35:30Z
INFO:yyyy-MM-dd'T'HH:mm:ssXX      =2013-10-07T21:35:30Z
INFO:yyyy-MM-dd'T'HH:mm:ssXXX     =2013-10-07T21:35:30Z
INFO:yyyy-MM-dd'T'HH:mm:ssZ       =2013-10-07T21:35:30+0000
INFO:yyyy-MM-dd'T'HH:mm:ssZZ      =2013-10-07T21:35:30+0000
INFO:EEE, dd MMM yyyy HH:mm:ss Z  =Mon, 07 Oct 2013 21:35:30 +0000
INFO:yyyy-MM-dd'T'HH:mm:ss+offset =2013-10-07T21:35:30+00:00
INFO:yyyy-MM-dd'T'HH:mm:ss'Z'     =2013-10-07T21:35:30Z
INFO:java.version = 1.7.0_15
INFO:TimeZone     =America/New_York
INFO:yyyy-MM-dd'T'HH:mm:ss        =2013-10-07T17:35:30
INFO:yyyy-MM-dd'T'HH:mm:ssz       =2013-10-07T17:35:30EDT
INFO:yyyy-MM-dd'T'HH:mm:sszz      =2013-10-07T17:35:30EDT
INFO:yyyy-MM-dd'T'HH:mm:sszzzz    =2013-10-07T17:35:30Eastern Daylight Time
INFO:yyyy-MM-dd'T'HH:mm:ssX       =2013-10-07T17:35:30-04
INFO:yyyy-MM-dd'T'HH:mm:ssXX      =2013-10-07T17:35:30-0400
INFO:yyyy-MM-dd'T'HH:mm:ssXXX     =2013-10-07T17:35:30-04:00
INFO:yyyy-MM-dd'T'HH:mm:ssZ       =2013-10-07T17:35:30-0400
INFO:yyyy-MM-dd'T'HH:mm:ssZZ      =2013-10-07T17:35:30-0400
INFO:EEE, dd MMM yyyy HH:mm:ss Z  =Mon, 07 Oct 2013 17:35:30 -0400
INFO:yyyy-MM-dd'T'HH:mm:ss+offset =2013-10-07T17:35:30-04:00
INFO:yyyy-MM-dd'T'HH:mm:ss'Z'     =2013-10-07T21:35:30Z
INFO:java.version = 1.7.0_15
INFO:TimeZone     =Europe/Amsterdam
INFO:yyyy-MM-dd'T'HH:mm:ss        =2013-10-07T23:35:30
INFO:yyyy-MM-dd'T'HH:mm:ssz       =2013-10-07T23:35:30CEST
INFO:yyyy-MM-dd'T'HH:mm:sszz      =2013-10-07T23:35:30CEST
INFO:yyyy-MM-dd'T'HH:mm:sszzzz    =2013-10-07T23:35:30Central European Summer Time
INFO:yyyy-MM-dd'T'HH:mm:ssX       =2013-10-07T23:35:30+02
INFO:yyyy-MM-dd'T'HH:mm:ssXX      =2013-10-07T23:35:30+0200
INFO:yyyy-MM-dd'T'HH:mm:ssXXX     =2013-10-07T23:35:30+02:00
INFO:yyyy-MM-dd'T'HH:mm:ssZ       =2013-10-07T23:35:30+0200
INFO:yyyy-MM-dd'T'HH:mm:ssZZ      =2013-10-07T23:35:30+0200
INFO:EEE, dd MMM yyyy HH:mm:ss Z  =Mon, 07 Oct 2013 23:35:30 +0200
INFO:yyyy-MM-dd'T'HH:mm:ss+offset =2013-10-07T23:35:30+02:00
INFO:yyyy-MM-dd'T'HH:mm:ss'Z'     =2013-10-07T21:35:30Z
INFO:Wintertime
INFO:java.version = 1.7.0_15
INFO:TimeZone     =Europe/Amsterdam
INFO:yyyy-MM-dd'T'HH:mm:ss        =2013-12-07T23:35:30
INFO:yyyy-MM-dd'T'HH:mm:ssz       =2013-12-07T23:35:30CET
INFO:yyyy-MM-dd'T'HH:mm:sszz      =2013-12-07T23:35:30CET
INFO:yyyy-MM-dd'T'HH:mm:sszzzz    =2013-12-07T23:35:30Central European Time
INFO:yyyy-MM-dd'T'HH:mm:ssX       =2013-12-07T23:35:30+01
INFO:yyyy-MM-dd'T'HH:mm:ssXX      =2013-12-07T23:35:30+0100
INFO:yyyy-MM-dd'T'HH:mm:ssXXX     =2013-12-07T23:35:30+01:00
INFO:yyyy-MM-dd'T'HH:mm:ssZ       =2013-12-07T23:35:30+0100
INFO:yyyy-MM-dd'T'HH:mm:ssZZ      =2013-12-07T23:35:30+0100
INFO:EEE, dd MMM yyyy HH:mm:ss Z  =Sat, 07 Dec 2013 23:35:30 +0100
INFO:yyyy-MM-dd'T'HH:mm:ss+offset =2013-12-07T23:35:30+01:00
INFO:yyyy-MM-dd'T'HH:mm:ss'Z'     =2013-12-07T22:35:30Z

Print AvailableIDs TimeZone

log.info "AvailableIDs TimeZone=" + TimeZone.getAvailableIDs()
output:
ACT,
AET,
Africa/Abidjan,
Africa/Accra,
Africa/Addis_Ababa,
Africa/Algiers,
Africa/Asmara,
Africa/Asmera,
Africa/Bamako,
Africa/Bangui,
Africa/Banjul,
Africa/Bissau,
Africa/Blantyre,
Africa/Brazzaville,
Africa/Bujumbura,
Africa/Cairo,
Africa/Casablanca,
Africa/Ceuta,
Africa/Conakry,
Africa/Dakar,
Africa/Dar_es_Salaam,
Africa/Djibouti,
Africa/Douala,
Africa/El_Aaiun,
Africa/Freetown,
Africa/Gaborone,
Africa/Harare,
Africa/Johannesburg,
Africa/Juba,
Africa/Kampala,
Africa/Khartoum,
Africa/Kigali,
Africa/Kinshasa,
Africa/Lagos,
Africa/Libreville,
Africa/Lome,
Africa/Luanda,
Africa/Lubumbashi,
Africa/Lusaka,
Africa/Malabo,
Africa/Maputo,
Africa/Maseru,
Africa/Mbabane,
Africa/Mogadishu,
Africa/Monrovia,
Africa/Nairobi,
Africa/Ndjamena,
Africa/Niamey,
Africa/Nouakchott,
Africa/Ouagadougou,
Africa/Porto-Novo,
Africa/Sao_Tome,
Africa/Timbuktu,
Africa/Tripoli,
Africa/Tunis,
Africa/Windhoek,
AGT,
America/Adak,
America/Anchorage,
America/Anguilla,
America/Antigua,
America/Araguaina,
America/Argentina/Buenos_Aires,
America/Argentina/Catamarca,
America/Argentina/ComodRivadavia,
America/Argentina/Cordoba,
America/Argentina/Jujuy,
America/Argentina/La_Rioja,
America/Argentina/Mendoza,
America/Argentina/Rio_Gallegos,
America/Argentina/Salta,
America/Argentina/San_Juan,
America/Argentina/San_Luis,
America/Argentina/Tucuman,
America/Argentina/Ushuaia,
America/Aruba,
America/Asuncion,
America/Atikokan,
America/Atka,
America/Bahia_Banderas,
America/Bahia,
America/Barbados,
America/Belem,
America/Belize,
America/Blanc-Sablon,
America/Boa_Vista,
America/Bogota,
America/Boise,
America/Buenos_Aires,
America/Cambridge_Bay,
America/Campo_Grande,
America/Cancun,
America/Caracas,
America/Catamarca,
America/Cayenne,
America/Cayman,
America/Chicago,
America/Chihuahua,
America/Coral_Harbour,
America/Cordoba,
America/Costa_Rica,
America/Creston,
America/Cuiaba,
America/Curacao,
America/Danmarkshavn,
America/Dawson_Creek,
America/Dawson,
America/Denver,
America/Detroit,
America/Dominica,
America/Edmonton,
America/Eirunepe,
America/El_Salvador,
America/Ensenada,
America/Fort_Wayne,
America/Fortaleza,
America/Glace_Bay,
America/Godthab,
America/Goose_Bay,
America/Grand_Turk,
America/Grenada,
America/Guadeloupe,
America/Guatemala,
America/Guayaquil,
America/Guyana,
America/Halifax,
America/Havana,
America/Hermosillo,
America/Indiana/Indianapolis,
America/Indiana/Knox,
America/Indiana/Marengo,
America/Indiana/Petersburg,
America/Indiana/Tell_City,
America/Indiana/Vevay,
America/Indiana/Vincennes,
America/Indiana/Winamac,
America/Indianapolis,
America/Inuvik,
America/Iqaluit,
America/Jamaica,
America/Jujuy,
America/Juneau,
America/Kentucky/Louisville,
America/Kentucky/Monticello,
America/Knox_IN,
America/Kralendijk,
America/La_Paz,
America/Lima,
America/Los_Angeles,
America/Louisville,
America/Lower_Princes,
America/Maceio,
America/Managua,
America/Manaus,
America/Marigot,
America/Martinique,
America/Matamoros,
America/Mazatlan,
America/Mendoza,
America/Menominee,
America/Merida,
America/Metlakatla,
America/Mexico_City,
America/Miquelon,
America/Moncton,
America/Monterrey,
America/Montevideo,
America/Montreal,
America/Montserrat,
America/Nassau,
America/New_York,
America/Nipigon,
America/Nome,
America/Noronha,
America/North_Dakota/Beulah,
America/North_Dakota/Center,
America/North_Dakota/New_Salem,
America/Ojinaga,
America/Panama,
America/Pangnirtung,
America/Paramaribo,
America/Phoenix,
America/Port_of_Spain,
America/Port-au-Prince,
America/Porto_Acre,
America/Porto_Velho,
America/Puerto_Rico,
America/Rainy_River,
America/Rankin_Inlet,
America/Recife,
America/Regina,
America/Resolute,
America/Rio_Branco,
America/Rosario,
America/Santa_Isabel,
America/Santarem,
America/Santiago,
America/Santo_Domingo,
America/Sao_Paulo,
America/Scoresbysund,
America/Shiprock,
America/Sitka,
America/St_Barthelemy,
America/St_Johns,
America/St_Kitts,
America/St_Lucia,
America/St_Thomas,
America/St_Vincent,
America/Swift_Current,
America/Tegucigalpa,
America/Thule,
America/Thunder_Bay,
America/Tijuana,
America/Toronto,
America/Tortola,
America/Vancouver,
America/Virgin,
America/Whitehorse,
America/Winnipeg,
America/Yakutat,
America/Yellowknife,
Antarctica/Casey,
Antarctica/Davis,
Antarctica/DumontDUrville,
Antarctica/Macquarie,
Antarctica/Mawson,
Antarctica/McMurdo,
Antarctica/Palmer,
Antarctica/Rothera,
Antarctica/South_Pole,
Antarctica/Syowa,
Antarctica/Vostok,
Arctic/Longyearbyen,
ART,
Asia/Aden,
Asia/Almaty,
Asia/Amman,
Asia/Anadyr,
Asia/Aqtau,
Asia/Aqtobe,
Asia/Ashgabat,
Asia/Ashkhabad,
Asia/Baghdad,
Asia/Bahrain,
Asia/Baku,
Asia/Bangkok,
Asia/Beirut,
Asia/Bishkek,
Asia/Brunei,
Asia/Calcutta,
Asia/Choibalsan,
Asia/Chongqing,
Asia/Chungking,
Asia/Colombo,
Asia/Dacca,
Asia/Damascus,
Asia/Dhaka,
Asia/Dili,
Asia/Dubai,
Asia/Dushanbe,
Asia/Gaza,
Asia/Harbin,
Asia/Hebron,
Asia/Ho_Chi_Minh,
Asia/Hong_Kong,
Asia/Hovd,
Asia/Irkutsk,
Asia/Istanbul,
Asia/Jakarta,
Asia/Jayapura,
Asia/Jerusalem,
Asia/Kabul,
Asia/Kamchatka,
Asia/Karachi,
Asia/Kashgar,
Asia/Kathmandu,
Asia/Katmandu,
Asia/Kolkata,
Asia/Krasnoyarsk,
Asia/Kuala_Lumpur,
Asia/Kuching,
Asia/Kuwait,
Asia/Macao,
Asia/Macau,
Asia/Magadan,
Asia/Makassar,
Asia/Manila,
Asia/Muscat,
Asia/Nicosia,
Asia/Novokuznetsk,
Asia/Novosibirsk,
Asia/Omsk,
Asia/Oral,
Asia/Phnom_Penh,
Asia/Pontianak,
Asia/Pyongyang,
Asia/Qatar,
Asia/Qyzylorda,
Asia/Rangoon,
Asia/Riyadh,
Asia/Riyadh87,
Asia/Riyadh88,
Asia/Riyadh89,
Asia/Saigon,
Asia/Sakhalin,
Asia/Samarkand,
Asia/Seoul,
Asia/Shanghai,
Asia/Singapore,
Asia/Taipei,
Asia/Tashkent,
Asia/Tbilisi,
Asia/Tehran,
Asia/Tel_Aviv,
Asia/Thimbu,
Asia/Thimphu,
Asia/Tokyo,
Asia/Ujung_Pandang,
Asia/Ulaanbaatar,
Asia/Ulan_Bator,
Asia/Urumqi,
Asia/Vientiane,
Asia/Vladivostok,
Asia/Yakutsk,
Asia/Yekaterinburg,
Asia/Yerevan,
AST,
Atlantic/Azores,
Atlantic/Bermuda,
Atlantic/Canary,
Atlantic/Cape_Verde,
Atlantic/Faeroe,
Atlantic/Faroe,
Atlantic/Jan_Mayen,
Atlantic/Madeira,
Atlantic/Reykjavik,
Atlantic/South_Georgia,
Atlantic/St_Helena,
Atlantic/Stanley,
Australia/ACT,
Australia/Adelaide,
Australia/Brisbane,
Australia/Broken_Hill,
Australia/Canberra,
Australia/Currie,
Australia/Darwin,
Australia/Eucla,
Australia/Hobart,
Australia/LHI,
Australia/Lindeman,
Australia/Lord_Howe,
Australia/Melbourne,
Australia/North,
Australia/NSW,
Australia/Perth,
Australia/Queensland,
Australia/South,
Australia/Sydney,
Australia/Tasmania,
Australia/Victoria,
Australia/West,
Australia/Yancowinna,
BET,
Brazil/Acre,
Brazil/DeNoronha,
Brazil/East,
Brazil/West,
BST,
Canada/Atlantic,
Canada/Central,
Canada/East-Saskatchewan,
Canada/Eastern,
Canada/Mountain,
Canada/Newfoundland,
Canada/Pacific,
Canada/Saskatchewan,
Canada/Yukon,
CAT,
CET,
Chile/Continental,
Chile/EasterIsland,
CNT,
CST,
CST6CDT,
CTT,
Cuba,
EAT,
ECT,
EET,
Egypt,
Eire,
EST,
EST5EDT,
Etc/GMT-0,
Etc/GMT-1,
Etc/GMT-10,
Etc/GMT-11,
Etc/GMT-12,
Etc/GMT-13,
Etc/GMT-14,
Etc/GMT-2,
Etc/GMT-3,
Etc/GMT-4,
Etc/GMT-5,
Etc/GMT-6,
Etc/GMT-7,
Etc/GMT-8,
Etc/GMT-9,
Etc/GMT,
Etc/GMT+0,
Etc/GMT+1,
Etc/GMT+10,
Etc/GMT+11,
Etc/GMT+12,
Etc/GMT+2,
Etc/GMT+3,
Etc/GMT+4,
Etc/GMT+5,
Etc/GMT+6,
Etc/GMT+7,
Etc/GMT+8,
Etc/GMT+9,
Etc/GMT0,
Etc/Greenwich,
Etc/UCT,
Etc/Universal,
Etc/UTC,
Etc/Zulu,
Europe/Amsterdam,
Europe/Andorra,
Europe/Athens,
Europe/Belfast,
Europe/Belgrade,
Europe/Berlin,
Europe/Bratislava,
Europe/Brussels,
Europe/Bucharest,
Europe/Budapest,
Europe/Chisinau,
Europe/Copenhagen,
Europe/Dublin,
Europe/Gibraltar,
Europe/Guernsey,
Europe/Helsinki,
Europe/Isle_of_Man,
Europe/Istanbul,
Europe/Jersey,
Europe/Kaliningrad,
Europe/Kiev,
Europe/Lisbon,
Europe/Ljubljana,
Europe/London,
Europe/Luxembourg,
Europe/Madrid,
Europe/Malta,
Europe/Mariehamn,
Europe/Minsk,
Europe/Monaco,
Europe/Moscow,
Europe/Nicosia,
Europe/Oslo,
Europe/Paris,
Europe/Podgorica,
Europe/Prague,
Europe/Riga,
Europe/Rome,
Europe/Samara,
Europe/San_Marino,
Europe/Sarajevo,
Europe/Simferopol,
Europe/Skopje,
Europe/Sofia,
Europe/Stockholm,
Europe/Tallinn,
Europe/Tirane,
Europe/Tiraspol,
Europe/Uzhgorod,
Europe/Vaduz,
Europe/Vatican,
Europe/Vienna,
Europe/Vilnius,
Europe/Volgograd,
Europe/Warsaw,
Europe/Zagreb,
Europe/Zaporozhye,
Europe/Zurich,
GB-Eire,
GB,
GMT,
GMT0,
Greenwich,
Hongkong,
HST,
Iceland,
IET,
Indian/Antananarivo,
Indian/Chagos,
Indian/Christmas,
Indian/Cocos,
Indian/Comoro,
Indian/Kerguelen,
Indian/Mahe,
Indian/Maldives,
Indian/Mauritius,
Indian/Mayotte,
Indian/Reunion,
Iran,
Israel,
IST,
Jamaica,
Japan,
JST,
Kwajalein,
Libya,
MET,
Mexico/BajaNorte,
Mexico/BajaSur,
Mexico/General,
Mideast/Riyadh87,
Mideast/Riyadh88,
Mideast/Riyadh89,
MIT,
MST,
MST7MDT,
Navajo,
NET,
NST,
NZ-CHAT,
NZ,
Pacific/Apia,
Pacific/Auckland,
Pacific/Chatham,
Pacific/Chuuk,
Pacific/Easter,
Pacific/Efate,
Pacific/Enderbury,
Pacific/Fakaofo,
Pacific/Fiji,
Pacific/Funafuti,
Pacific/Galapagos,
Pacific/Gambier,
Pacific/Guadalcanal,
Pacific/Guam,
Pacific/Honolulu,
Pacific/Johnston,
Pacific/Kiritimati]
Pacific/Kosrae,
Pacific/Kwajalein,
Pacific/Majuro,
Pacific/Marquesas,
Pacific/Midway,
Pacific/Nauru,
Pacific/Niue,
Pacific/Norfolk,
Pacific/Noumea,
Pacific/Pago_Pago,
Pacific/Palau,
Pacific/Pitcairn,
Pacific/Pohnpei,
Pacific/Ponape,
Pacific/Port_Moresby,
Pacific/Rarotonga,
Pacific/Saipan,
Pacific/Samoa,
Pacific/Tahiti,
Pacific/Tarawa,
Pacific/Tongatapu,
Pacific/Truk,
Pacific/Wake,
Pacific/Wallis,
Pacific/Yap,
PLT,
PNT,
Poland,
Portugal,
PRC,
PRT,
PST,
PST8PDT,
ROK,
Singapore,
SST,
SystemV/AST4,
SystemV/AST4ADT,
SystemV/CST6,
SystemV/CST6CDT,
SystemV/EST5,
SystemV/EST5EDT,
SystemV/HST10,
SystemV/MST7,
SystemV/MST7MDT,
SystemV/PST8,
SystemV/PST8PDT,
SystemV/YST9,
SystemV/YST9YDT,
Turkey,
UCT,
Universal,
US/Alaska,
US/Aleutian,
US/Arizona,
US/Central,
US/East-Indiana,
US/Eastern,
US/Hawaii,
US/Indiana-Starke,
US/Michigan,
US/Mountain,
US/Pacific-New,
US/Pacific,
US/Samoa,
UTC,
VST,
W-SU,
WET,
Zulu,

zaterdag 5 oktober 2013

Parsing subtitle srt files and add seconds Bash OSX

Same as java example writen in bash osx shell.
#!/bin/sh
#
# Check input parameters
#
if [[ -z ${2} ]]; then
 echo "Usage:SubTitle.sh filename.srt +5|-5"
 exit
fi

FILENAME="$1"
DIFFSECONDS="$2"

#
# 00:41:01,345
#
function addTimeSeconds(){
 mMilli=`echo $1|cut -d',' -f2`   # 345
 mSeconds=`echo $1|cut -d',' -f1` # 00:41:01
 # Parse time to seconds
 mSeconds=$(date -j -f "%Y-%m-%d %H:%M:%S" "2000-01-01 ${mSeconds}" "+%s")
 # Add extra seconds
 mSeconds=$((mSeconds + $DIFFSECONDS))
 # Parse time to format HH:MM:SS
 mSeconds=`date -j -f "%s" "$mSeconds" "+%H:%M:%S"`
 printf "${mSeconds},${mMilli}"
}

function addTime(){
 mFromTime=$(addTimeSeconds "$1")
 mToTime=$(addTimeSeconds "$3")
 echo "${mFromTime} --> ${mToTime}"
}

while read line; do
 if [[ $line == *"-->"* ]] ; then
  addTime $line
 else
  echo "$line"
 fi
done < "${FILENAME}"

Parsing subtitle srt files and add seconds Java

Changing the time of subtitle file .srt. the structure for the srt file is:
1    A numeric counter identifying each sequential subtitle
2    The time that the subtitle should appear on the screen, followed by " --> " and the time it should disappear
3    Subtitle text itself on one or more lines
4    A blank line containing no text indicating the end of this subtitle[10]
For storing one item in a javaobject the class TextStruc is used. An Arraylist of string is used for storing the text lines. The constructor splits the date fields and stores them in mFromTime and mToTime. The function addSeconds returns a string with the extra seconds.
package org.sysgarden;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

//
// 1
// 00:00:00,500 --> 00:00:02,207
// Once upon a time ...
// [newline]
// 2 
//
public class TextStruct {
    private static SimpleDateFormat mSdf = new SimpleDateFormat("hh:mm:ss,SSS"); 
    private ArrayList mTextLines = null;
    private int  mDiffSeconds= 0;
    private Date mFromTime   = null;
    private Date mToTime     = null;

    TextStruct(ArrayList textLines){
      mTextLines=textLines;
      String[] splited = mTextLines.get(1).split(" ");
      try {
       mFromTime=mSdf.parse(splited[0]);
       mToTime=mSdf.parse(splited[2]);
      } catch( Exception e){
       e.printStackTrace();
      }
    }

    public String addSeconds(int aDiffSeconds){
      mDiffSeconds = aDiffSeconds;
      String newline=System.getProperty("line.separator");
      String s="";
      for (int i=0;i< mTextLines.size(); i++ ){
        if (i==1) {
          s+=mSdf.format(addTime(mFromTime)) + " --> " + mSdf.format(addTime(mToTime)) +newline;
        } else {
   s+=mTextLines.get(i) + newline;
        }
      }
      return s;
    }
    
    private Date addTime(Date d){
      Calendar cal=Calendar.getInstance();
      cal.setTime(d);
      cal.add(Calendar.SECOND, mDiffSeconds);
      return cal.getTime();
    }
  }
The second class is for reading the srt file and parsing it.
package org.sysgarden;

import java.io.*;
import java.util.ArrayList;

//
// java SubTitle "movie.srt" + 12
// java SubTitle "movie.srt" - 12
// 
public class SubTitle {
 public static void main (String[] args){
  if (args==null || args.length != 3) {
   System.out.println("Number argument does not match:3!=" + args.length );
   printUsage();
   System.exit(0);
  }
  SubTitle subTitle=new SubTitle(args[1], args[2]);
  subTitle.readFile(args[0]);
  subTitle.print();
 } 
 public static void printUsage (){
    System.out.println("use:java org.sysgarden.SubTitle filename +|- seconds");
 }
 
 private ArrayList items=new ArrayList();
 public static int diff_seconds=1;

 public SubTitle(String pm, String sec){
  int plusminus=1;
  int seconds=0;
  if ("-".equals(pm)){
    plusminus=-1;  
  }
  try {
    seconds=Integer.parseInt(sec);
  } catch(Exception e ){
    printUsage();
    e.getMessage();
    System.exit(0);
  }
   diff_seconds=plusminus*seconds;
   System.out.println("diff="+diff_seconds);
 }

 public void readFile(String filename) {
  try {
   // Open the file that is the first 
   FileInputStream fstream = new FileInputStream(filename);
   // Get the object of DataInputStream
   DataInputStream in = new DataInputStream(fstream);
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
   String strLine="";
   ArrayList lines=new ArrayList();
   //Read File Line By Line
   while ((strLine = br.readLine()) != null)   {
    // Print the content on the console
    System.out.println (strLine);
    if (isEmpty(strLine)){
     items.add(new TextStruct(lines));
     lines= new ArrayList();
    } else {
     lines.add(strLine);
    }
   }
   if (lines.size() > 1)
     items.add(new TextStruct(lines));
   //Close the input stream
   br.close();
   in.close();
  } catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
  }
 }

 public void print() {
   for (int i=0; i < items.size(); i++){
     System.out.println (items.get(i).addSeconds(diff_seconds));
   }  
 }

 private boolean isEmpty(String s){
  if(s == null)          return true;
  if(s.trim().isEmpty()) return true;
  return false;
 }
}

woensdag 3 oktober 2012

Bash cheatsheet

#tar the directory mydir (and its files/subdirectories) into a tar file named foo.tgz.
tar cvzf foo.tgz mydir 
#see a tar file s table of contents
tar tzf foo.tgz
#extract the contents of a tar file
tar xvzf foo.tgz
#find biggest dir
du -k | egrep -v "\./.+/"|sort -n