@Test public void emptyHasNoMessages() { assertThat(streamer.parseNextMessage(), nullValue()); }
@Override public VehicleMessage parseNextMessage() { InputStream input = new ByteArrayInputStream(mBuffer.toByteArray()); VehicleMessage message = null; int bytesRemaining = mBuffer.size(); while(message == null) { try { int firstByte = input.read(); bytesRemaining -= 1; if (firstByte == -1) { return null; } int size = CodedInputStream.readRawVarint32(firstByte, input); if(size > 0 && bytesRemaining >= size) { message = BinaryFormatter.deserialize( ByteStreams.limit(input, size)); } else { break; } } catch(IOException e) { Log.e(TAG, "Unexpected errror copying buffers"); } catch(UnrecognizedMessageTypeException e) { Log.w(TAG, "Deserialized protobuf had was unrecognized message type", e); } } if(message != null) { mBuffer = new ByteArrayOutputStream(); try { IOUtils.copy(input, mBuffer); } catch(IOException e) { Log.e(TAG, "Unexpected error copying buffers"); } } return message; }
BinaryStreamer extends VehicleMessageStreamer { @Override public VehicleMessage parseNextMessage() { InputStream input = new ByteArrayInputStream(mBuffer.toByteArray()); VehicleMessage message = null; int bytesRemaining = mBuffer.size(); while(message == null) { try { int firstByte = input.read(); bytesRemaining -= 1; if (firstByte == -1) { return null; } int size = CodedInputStream.readRawVarint32(firstByte, input); if(size > 0 && bytesRemaining >= size) { message = BinaryFormatter.deserialize( ByteStreams.limit(input, size)); } else { break; } } catch(IOException e) { Log.e(TAG, "Unexpected errror copying buffers"); } catch(UnrecognizedMessageTypeException e) { Log.w(TAG, "Deserialized protobuf had was unrecognized message type", e); } } if(message != null) { mBuffer = new ByteArrayOutputStream(); try { IOUtils.copy(input, mBuffer); } catch(IOException e) { Log.e(TAG, "Unexpected error copying buffers"); } } return message; } }
BinaryStreamer extends VehicleMessageStreamer { @Override public VehicleMessage parseNextMessage() { InputStream input = new ByteArrayInputStream(mBuffer.toByteArray()); VehicleMessage message = null; int bytesRemaining = mBuffer.size(); while(message == null) { try { int firstByte = input.read(); bytesRemaining -= 1; if (firstByte == -1) { return null; } int size = CodedInputStream.readRawVarint32(firstByte, input); if(size > 0 && bytesRemaining >= size) { message = BinaryFormatter.deserialize( ByteStreams.limit(input, size)); } else { break; } } catch(IOException e) { Log.e(TAG, "Unexpected errror copying buffers"); } catch(UnrecognizedMessageTypeException e) { Log.w(TAG, "Deserialized protobuf had was unrecognized message type", e); } } if(message != null) { mBuffer = new ByteArrayOutputStream(); try { IOUtils.copy(input, mBuffer); } catch(IOException e) { Log.e(TAG, "Unexpected error copying buffers"); } } return message; }  }
BinaryStreamer extends VehicleMessageStreamer { @Override public VehicleMessage parseNextMessage() { InputStream input = new ByteArrayInputStream(mBuffer.toByteArray()); VehicleMessage message = null; int bytesRemaining = mBuffer.size(); while(message == null) { try { int firstByte = input.read(); bytesRemaining -= 1; if (firstByte == -1) { return null; } int size = CodedInputStream.readRawVarint32(firstByte, input); if(size > 0 && bytesRemaining >= size) { message = BinaryFormatter.deserialize( ByteStreams.limit(input, size)); } else { break; } } catch(IOException e) { Log.e(TAG, "Unexpected errror copying buffers"); } catch(UnrecognizedMessageTypeException e) { Log.w(TAG, "Deserialized protobuf had was unrecognized message type", e); } } if(message != null) { mBuffer = new ByteArrayOutputStream(); try { IOUtils.copy(input, mBuffer); } catch(IOException e) { Log.e(TAG, "Unexpected error copying buffers"); } } return message; }  @Override VehicleMessage parseNextMessage(); @Override VehicleMessage parseMessage(String line); @Override String getRawMessage(); @Override byte[] serializeForStream(VehicleMessage message); static void dumpToLog(byte[] bytes, int length); @Override void receive(byte[] bytes, int length); }
BinaryStreamer extends VehicleMessageStreamer { @Override public VehicleMessage parseNextMessage() { InputStream input = new ByteArrayInputStream(mBuffer.toByteArray()); VehicleMessage message = null; int bytesRemaining = mBuffer.size(); while(message == null) { try { int firstByte = input.read(); bytesRemaining -= 1; if (firstByte == -1) { return null; } int size = CodedInputStream.readRawVarint32(firstByte, input); if(size > 0 && bytesRemaining >= size) { message = BinaryFormatter.deserialize( ByteStreams.limit(input, size)); } else { break; } } catch(IOException e) { Log.e(TAG, "Unexpected errror copying buffers"); } catch(UnrecognizedMessageTypeException e) { Log.w(TAG, "Deserialized protobuf had was unrecognized message type", e); } } if(message != null) { mBuffer = new ByteArrayOutputStream(); try { IOUtils.copy(input, mBuffer); } catch(IOException e) { Log.e(TAG, "Unexpected error copying buffers"); } } return message; }  @Override VehicleMessage parseNextMessage(); @Override VehicleMessage parseMessage(String line); @Override String getRawMessage(); @Override byte[] serializeForStream(VehicleMessage message); static void dumpToLog(byte[] bytes, int length); @Override void receive(byte[] bytes, int length);  }