public static Object readObject ( final Socket clientSocket ) throws IOException , ClassNotFoundException { ObjectInputStream in = null ; Object objectToReturn = null ; try { in = new ObjectInputStream ( new BufferedInputStream ( clientSocket . getInputStream ( ) ) ) ; while ( true ) { objectToReturn = in . readObject ( ) ; if ( objectToReturn != null ) { break ; } } in . close ( ) ; clientSocket . close ( ) ; } catch ( final IOException e ) { LOGGER . error ( "IOException occured by trying to read the object." , e ) ; throw e ; } catch ( final ClassNotFoundException e ) { LOGGER . error ( "ClassNotFoundException occured by trying to read the object from the socket." , e ) ; throw e ; } finally { try { if ( in != null ) { in . close ( ) ; } close ( clientSocket ) ; } catch ( final IOException e ) { LOGGER . error ( "IOException occured by trying to close the socket." , e ) ; throw e ; } } return objectToReturn ; }
Reads an object from the given socket object .