private void sendDependencyTable ( final int dependencyId ) throws IOException { final byte [ ] dependencyBytes = nextDependencyAsBytes ( dependencyId ) ; if ( dependencyBytes == null ) { m_connection . m_socket . getOutputStream ( ) . write ( Connection . kErrorCode_DependencyNotFound ) ; return ; } // 1 for response code + 4 for dependency length prefix + dependencyBytes.length final ByteBuffer message = ByteBuffer . allocate ( 1 + 4 + dependencyBytes . length ) ; // write the response code message . put ( ( byte ) Connection . kErrorCode_DependencyFound ) ; // write the dependency's length prefix message . putInt ( dependencyBytes . length ) ; // finally, write dependency table itself message . put ( dependencyBytes ) ; message . rewind ( ) ; if ( m_connection . m_socketChannel . write ( message ) != message . capacity ( ) ) { throw new IOException ( "Unable to send dependency table to client. Attempted blocking write of " + message . capacity ( ) + " but not all of it was written" ) ; } }
Retrieve a dependency table and send it via the connection . If no table is available send a response code indicating such . The message is prepended with two lengths . One length is for the network layer and is the size of the whole message not including the length prefix .