a simple trick to read and write the object through protobuff, is to create an additional wrapper .proto

syntax = "proto3";option java_package = "models";message Model{
int64 id =1;
string name =2;

then wrap it

message Models {
repeated Model models = 1;

then instead of read and write the objects one by one through java stream. it could be read and write in one go through Models.

ModelsClass.Models models = ModelsClass.Models.newBuilder().mergeFrom(fileInputStream).build();models.writeTo(fileOutputStream);



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store