Posts

Showing posts from March, 2017

Featured Post

Netty inbound / outbound socket exception handler

import io . netty . channel .*; import java . net . SocketAddress ; public class ExceptionHandler extends ChannelDuplexHandler { @Override public void exceptionCaught ( ChannelHandlerContext ctx , Throwable cause ) { // Uncaught exceptions from inbound handlers will propagate up to this handler } @Override public void connect ( ChannelHandlerContext ctx , SocketAddress remoteAddress , SocketAddress localAddress , ChannelPromise promise ) { ctx . connect ( remoteAddress , localAddress , promise . addListener ( new ChannelFutureListener () { @Override public void operationComplete ( ChannelFuture future ) { if (! future . isSuccess ()) { // Handle connect exception here... } } })); } @Override public void write ( ChannelHandlerContext ctx , Object msg , ChannelPromise promise ) { ...

sh read file line by line

#!/bin/bash   while read LINE   do       IFS='/';       read -r -a array <<< "$LINE"       DATA='';      for index in "${!array[@]}"       do          if [  $2 == "${array[index]}" ]          then                DATA="${array[index]}"                c=0;                while [  $c -le $index ]                 do                                  echo -n "${array[c]}/"                  c=$((  $c + 1  ));                 done            echo ''       ...