package decoder;

import com.google.protobuf.util.JsonFormat;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import proto.SensorData.Pose;

/** Decode data from the proto format to JSON. */
public class Decoder {
  public static void decode(InputStream dataStream, OutputStream outputStream) {

    // At some point it would make sense to have this data read in chunks of the
    // data file and include headers in the proto definitions so we could
    // address issues with large files, stuff not fitting into RAM, etc.
    try {
      int i = 0;
      PrintWriter output = new PrintWriter(outputStream);
      Pose currentPose = Pose.parseDelimitedFrom(dataStream);
      ;
      for (; currentPose != null && i != 10; i++) {
        output.write(JsonFormat.printer().print(currentPose));
        currentPose = Pose.parseDelimitedFrom(dataStream);
      }
      output.close();
      // Now convert the data we have streamed in to JSON.parseFrom
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

@@ -568,25 +568,8 @@
 y %7B%0A
-      int i = 0;%0A
     
@@ -694,23 +694,114 @@
     
-;%0A      for (; 
+// Read until nothing left to read, in which case null is returned.%0A      output.write(%22%5B%22);%0A      while (
 curr
@@ -819,24 +819,8 @@
 null
- && i != 10; i++
 ) %7B%0A
@@ -951,99 +951,191 @@
     
-%7D%0A      output.close();%0A      // Now convert the data we have streamed in to JSON.parseFrom
+  // Write ',' on all but last entry.%0A        if (currentPose != null) output.write(%22,%22);%0A      %7D%0A      output.write(%22%5D%22);%0A      // Close the PrintWriter stream.%0A      output.close();
 %0A   

Fix decoder formatting