@ Override public NetworkConnectionServiceMessage decode ( final byte [ ] data ) { try ( final ByteArrayInputStream bais = new ByteArrayInputStream ( data ) ) { try ( final DataInputStream dais = new DataInputStream ( bais ) ) { final String connFactoryId = dais . readUTF ( ) ; final Identifier srcId = factory . getNewInstance ( dais . readUTF ( ) ) ; final Identifier destId = factory . getNewInstance ( dais . readUTF ( ) ) ; final int size = dais . readInt ( ) ; final List list = new ArrayList ( size ) ; final Codec codec = connFactoryMap . get ( connFactoryId ) . getCodec ( ) ; Boolean isStreamingCodec = isStreamingCodecMap . get ( codec ) ; if ( isStreamingCodec == null ) { isStreamingCodec = codec instanceof StreamingCodec ; isStreamingCodecMap . putIfAbsent ( codec , isStreamingCodec ) ; } if ( isStreamingCodec ) { for ( int i = 0 ; i < size ; i ++ ) { list . add ( ( ( StreamingCodec ) codec ) . decodeFromStream ( dais ) ) ; } } else { for ( int i = 0 ; i < size ; i ++ ) { final int byteSize = dais . readInt ( ) ; final byte [ ] bytes = new byte [ byteSize ] ; if ( dais . read ( bytes ) == - 1 ) { LOG . log ( Level . FINE , "No data read because end of stream was reached" ) ; } list . add ( codec . decode ( bytes ) ) ; } } return new NetworkConnectionServiceMessage ( connFactoryId , srcId , destId , list ) ; } } catch ( final IOException e ) { throw new RuntimeException ( "IOException" , e ) ; } }
Decodes a network connection service message from bytes .