< prev index next >

test/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -26,11 +26,13 @@
    @modules java.desktop/com.sun.media.sound
 */
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
 import com.sun.media.sound.*;
 

@@ -52,17 +54,17 @@
             testarray[i] *= 0.3;
         }
         test_byte_array = new byte[testarray.length*2];
         AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
         test_file = File.createTempFile("test", ".raw");
-        FileOutputStream fos = new FileOutputStream(test_file);
+        try (FileOutputStream fos = new FileOutputStream(test_file)) {
         fos.write(test_byte_array);
     }
+    }
 
     static void tearDown() throws Exception {
-        if(!test_file.delete())
-            test_file.deleteOnExit();
+        Files.delete(Paths.get(test_file.getAbsolutePath()));
     }
 
     public static void main(String[] args) throws Exception {
         try
         {

@@ -74,11 +76,13 @@
                     buff = new ModelByteBuffer(test_file);
                 else
                     buff = new ModelByteBuffer(test_byte_array);
 
                 byte[] b = new byte[test_byte_array.length];
-                buff.getInputStream().read(b);
+                try (InputStream is = buff.getInputStream()) {
+                    is.read(b);
+                }
                 for (int j = 0; j < b.length; j++)
                     if(b[i] != test_byte_array[i])
                          throw new RuntimeException("Byte array compare fails!");
             }
         }
< prev index next >