Did you test or debug your solution? 

You read MSG from the file twice: in.read(obj.msg,obj.length)!!!