json trace: Pass the input stream to read metadata

In the sorting job, the events are all read and metadata can be located
at the end of the file. To avoid having to read the events again to get
to the metadata, the parser is passed to the processMetadata method.

[added] File stream is passed to SortingJob#processMetadata of Json traces

Change-Id: Id021dc78429901cd191aba18ba549e9ef6002704
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/176088
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
diff --git a/jsontrace/org.eclipse.tracecompass.jsontrace.core/src/org/eclipse/tracecompass/internal/jsontrace/core/job/SortingJob.java b/jsontrace/org.eclipse.tracecompass.jsontrace.core/src/org/eclipse/tracecompass/internal/jsontrace/core/job/SortingJob.java
index c7a4af4..39433c2 100644
--- a/jsontrace/org.eclipse.tracecompass.jsontrace.core/src/org/eclipse/tracecompass/internal/jsontrace/core/job/SortingJob.java
+++ b/jsontrace/org.eclipse.tracecompass.jsontrace.core/src/org/eclipse/tracecompass/internal/jsontrace/core/job/SortingJob.java
@@ -216,8 +216,8 @@
                  * This resource is added to a priority queue and then removed at the very end.
                  */
                 BufferedInputStream createParser = new BufferedInputStream(new FileInputStream(traceling));
-                while (data != '{') {
-                    data = parser.read();
+                while (data != '[') {
+                    data = createParser.read();
                     if (data == -1) {
                         break;
                     }
@@ -236,7 +236,7 @@
                 return Status.CANCEL_STATUS;
             }
 
-            processMetadata(trace, dir);
+            processMetadata(trace, dir, parser);
 
             File file = new File(dir + File.separator + new File(trace.getPath()).getName());
             boolean success = file.createNewFile();
@@ -289,14 +289,32 @@
     }
 
     /**
-     * Process whatever metadata that can be found after the event list in the trace
-     * file file
+     * Process whatever metadata that can be found after the event list in the
+     * trace file file
+     *
+     * @param trace
+     *            the trace to be sort
+     * @param dir
+     *            the path to the trace file
+     * @param parser
+     *            The file parser, position at the end of the events
+     * @throws IOException
+     *             Exceptions thrown by reading file
+     */
+    protected void processMetadata(ITmfTrace trace, String dir, BufferedInputStream parser) throws IOException {
+        this.processMetadata(trace, dir);
+    }
+
+    /**
+     * Process whatever metadata that can be found after the event list in the
+     * trace file file
      *
      * @param trace
      *            the trace to be sort
      * @param dir
      *            the path to the trace file
      * @throws IOException
+     *             Exceptions thrown by reading file
      */
     protected abstract void processMetadata(ITmfTrace trace, String dir) throws IOException;