tmf: Switch tmf.core.tests to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / CreateTestFiles.java
index b9c47baafea55bcef400ba0dfad1f5d356c8fab0..2400dc59401e0d241ab1bd83b69a4bff64b02362 100644 (file)
@@ -86,27 +86,28 @@ public class CreateTestFiles {
      * @throws FileNotFoundException
      * @throws IOException
      */
-    private static void createTestFile(final String file, final int size, final boolean monotonic, final boolean odd) throws FileNotFoundException, IOException {
-        DataOutputStream out;
+    private static void createTestFile(final String file, final int size,
+            final boolean monotonic, final boolean odd)
+            throws IOException {
         System.out.println("Creating " + file);
-        out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
+        try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));) {
 
-        final Random generator = new Random(19580427 + size);
-        long ts = (monotonic && odd) ? -1 : 0;
-        for (int i = 0; i < size; i++) {
-            ts += monotonic ? 2 : generator.nextInt(10);
-            final int sourceIndex = i % NB_SOURCES;
-            final int typeIndex   = i % NB_TYPES;
-            out.writeLong(ts);                      // Timestamp
-            out.writeUTF("Source-" + sourceIndex);  // Source
-            out.writeUTF("Type-"   + typeIndex);    // Type
-            out.writeInt(i + 1);                    // Reference (event #)
-            for (int j = 0; j < typeIndex; j++) {
-                out.writeUTF("Field-" + sourceIndex + "-" + j);
+            final Random generator = new Random(19580427 + size);
+            long ts = (monotonic && odd) ? -1 : 0;
+            for (int i = 0; i < size; i++) {
+                ts += monotonic ? 2 : generator.nextInt(10);
+                final int sourceIndex = i % NB_SOURCES;
+                final int typeIndex = i % NB_TYPES;
+                out.writeLong(ts); // Timestamp
+                out.writeUTF("Source-" + sourceIndex); // Source
+                out.writeUTF("Type-" + typeIndex); // Type
+                out.writeInt(i + 1); // Reference (event #)
+                for (int j = 0; j < typeIndex; j++) {
+                    out.writeUTF("Field-" + sourceIndex + "-" + j);
+                }
             }
+            out.flush();
         }
-        out.flush();
-        out.close();
     }
 
 }
This page took 0.025438 seconds and 5 git commands to generate.