/** * Add additional bytes to the buffer from the data source. * * @param bytes an array of bytes received from the interface. * @param length number of bytes received, and thus the amount that should * be read from the array. */ public void receive(byte[] bytes, int length) { mBytesReceived += length; logTransferStats(); }
@Override public void receive(byte[] bytes, int length) { super.receive(bytes, length); mBuffer.write(bytes, 0, length); } }
mStreamHandler.receive(bytes, received); VehicleMessage message; while((message = mStreamHandler.parseNextMessage()) != null) { handleMessage(message);
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"); } }
@Override public void receive(byte[] bytes, int length) { super.receive(bytes, length); // Creating a new String object for each message causes the // GC to go a little crazy, but I don't see another obvious way // of converting the byte[] to something the StringBuilder can // accept (either char[] or String). See #151. mBuffer.append(new String(bytes, 0, length)); }