clear buffer before reading NIO socket
avoid chain of exception if close fail
added license header