How to split String in words and populate an array

Here a simply method to split a string in words and generate an array.
In this case I use a Length param to limit substring size.

 


...

public static String[] splitStringInWordsAndCreateArrayWithLineInSize(String input,Integer lineLength){
		String[] words = input.split(" ");
 		List<String> list = new ArrayList<String>();
 		StringBuilder line = new StringBuilder();
 		for (int x = 0; x < words.length; x++) {
 			
 			
 			Boolean c = ((line.toString()+words[x]+" ").length()<lineLength);
 			if(c){
 				line.append(words[x]).append(" ");
 			}else{
 				list.add(line.toString());
 				line = new StringBuilder(words[x]).append(" ");
 			}
 		}
 		if(line.toString().length()>0){
 			list.add(line.toString());	
 		}
 		
 		Object[] arrObj = list.toArray();
 		String[] arrString = Arrays.copyOf(arrObj, arrObj.length, String[].class);
 		
		return arrString;
	}

...

And here unit test:


...

@Test
	 	public void testSplitStringInWordsAndCreateArrayWithLineInSize(){
	 		String s = "Prodotti tricologici per la cura e la bellezza dei capelli,quali shampoo, lozioni per capelli, preparati per ondulare icapelli, preparati per effettuare la permanente dei capelli,tinture per capelli, gel per capelli, lacche e fissatori percapelli,preparati per ravvivare il colore dei capelli . ";
	 		Integer lineLength = 62;
	 		String[] out = FYStringUtils.splitStringInWordsAndCreateArrayWithLineInSize(s, lineLength);
	 		StringBuilder rebuild = new StringBuilder();
	 		for(int x=0;x<out.length;x++){
	 			//System.out.println("x-"+out[x]);
	 			assertThat(out.length<lineLength).isTrue();
	 			rebuild.append(out[x]);
	 		}
	 		
	 		
	 		assertThat(rebuild.toString()).isEqualTo(s);
	 		
	 	}

...

Add more Swap on linux Vm

How to add more swap on a linux Vm.
It can be used on a physical machine too but remember that swap is store on a file and not in a dedicate partition.

#########################sWap File
#Create Local Folder
mkdir -p /usr/local/swap/

#Create a 2Gb Local File to store swap
dd if=/dev/zero of=/usr/local/swap/swapfile1 bs=1024 count=2097152 #2gb 4194304
mkswap /usr/local/swap/swapfile1

#set Grant On File
cd /usr/local/swap/
chown root:root swapfile1
chmod 0600 swapfile1

#Enable Swap
swapon swapfile1

Add this line in /ect/fstab to load swap on system startup:


/usr/local/swap/swapfile1 swap swap defaults 0 0

How to Solve CWWIM4551E Change handler was not …

Using Websphere Portal With domino and some Other Ldap you can come across this error:

CWWIM4551E Change handler was not defined for repository type ‘YOURTYPE’ .at com.ibm.ws.wim.adapter.ldap.change.ChangeHandlerFactory.getChangeHandler(ChangeHandlerFactory.java:95)

To solve this go to:

<profileRoot>/config/cells/<cellName>/wim/config/wimconfig.xml

 

Find this parameter “supportChangeLog” relative to your ldap and set it to “none” if it doesn’t support Change Log (for example domino doesn’t).

 

EXAMPLE:


<config:repositories xsi:type="config:LdapRepositoryType" adapterClassName="com.ibm.ws.wim.adapter.ldap.LdapAdapter"
id="YOURID" isExtIdUnique="true" supportAsyncMode="false" supportExternalName="false"
supportPaging="false" supportSorting="false" supportTransactions="false"

supportChangeLog="none"

certificateFilter="" certificateMapMode="exactdn" ldapServerType="NDS" translateRDN="false">

 

Start a db2 instance as daemon

Just because I always have problem with db2 autostart I’ve decided to use this simply, fast and flexible script:


#!/bin/sh
### BEGIN INIT INFO
# Provides:          IBM-Db2-db2inst1
# Required-Start:    $local_fs $remote_fs $network $syslog sshd
# Required-Stop:     $local_fs $remote_fs $network $syslog sshd
# Default-Start:     3 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop IBM DB2 instance
### END INIT INFO
#
# IBM Db2 : This init.d script starts the db2inst1 instance

NAME=`basename $0`

instance_User=db2inst1



start() {
    echo -n $"Starting ${NAME} service: "
       $tds_start ; > /dev/null
	   su - $instance_User -c "db2start"  
    ret=$? 
    if [ $ret -eq 0 ]
    then
            echo "${NAME} Started."
    else
            echo "${NAME} Starting Failed!"
            exit 1
    fi
    echo
}

stop() {
    echo -n $"Starting ${NAME} service: "
       $tds_start ; > /dev/null
	   su - $instance_User -c "db2stop"  
    ret=$? 
    if [ $ret -eq 0 ]
    then
            echo "${NAME} Started."
    else
            echo "${NAME} Starting Failed!"
            exit 1
    fi
    echo
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;		
    *)
        echo $"Usage: $0 {start|stop}"
        exit 1
esac
exit 0

Execute command on all Db2 instances

Here the script I use to verify all backup on all dbs on all instances.
I use it with the “db2-check-backup.sh” documented Here

#!/bin/sh
UNIQUE=`date +%s`
LPATH=$(pwd)
INST=/tmp/instances.$UNIQUE
OUT=/tmp/outallinst.$UNIQUE
 
/opt/ibm/db2/V9.7/bin/db2ilist > $INST
 
while read LN; do
 echo "###########"  $LN  >> $OUT
 $LPATH/db2-check-backup.sh $LN >>$OUT
done < $INST
 
cat $OUT
rm $OUT
rm $INST