public void receive(VehicleMessage command) throws DataSinkException { if(isConnected()) { VehicleMessageStreamer streamer; synchronized(this) { streamer = mStreamHandler; if(streamer == null) { // See https://github.com/openxc/openxc-android/issues/181 streamer = new JsonStreamer(); Log.i(getTag(), "Payload format unknown, guessing JSON"); } } try { if(!write(streamer.serializeForStream(command))) { throw new DataSinkException("Unable to send command"); } } catch(SerializationException e) { throw new DataSinkException( "Unable to serialize command for sending", e); } } else { throw new DataSinkException("Not connected"); } }