8160217: JavaSound should clean up resources better
authorserb
Tue, 23 Aug 2016 20:45:35 +0300
changeset 40718 fe2adbe4d101
parent 40717 02500a642a8e
child 40719 4ae72a69bd3b
8160217: JavaSound should clean up resources better Reviewed-by: prr
jdk/src/java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetRoot.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Load.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/LoadAll.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArray.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArrayIntInt.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFile.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFileLongLong.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Available.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Close.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkReset.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkSupported.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Read.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByte.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByteIntInt.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Skip.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLong.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLong.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLongBoolean.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Unload.java
jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/WriteTo.java
jdk/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/OpenStream.java
jdk/test/javax/sound/sampled/AudioInputStream/FrameLengthAfterConversion.java
jdk/test/javax/sound/sampled/spi/AudioFileWriter/WriteUnsupportedAudioFormat.java
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2013, 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
@@ -200,11 +200,13 @@
 
     public void writeTo(OutputStream out) throws IOException {
         if (root.file != null && root.buffer == null) {
-            InputStream is = getInputStream();
-            byte[] buff = new byte[1024];
-            int ret;
-            while ((ret = is.read(buff)) != -1)
-                out.write(buff, 0, ret);
+            try (InputStream is = getInputStream()) {
+                byte[] buff = new byte[1024];
+                int ret;
+                while ((ret = is.read(buff)) != -1) {
+                    out.write(buff, 0, ret);
+                }
+            }
         } else
             out.write(array(), (int) arrayOffset(), (int) capacity());
     }
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,7 +28,9 @@
 
 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.*;
 
@@ -54,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
@@ -76,7 +78,9 @@
                     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!");
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetRoot.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/GetRoot.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Load.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Load.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,7 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -54,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/LoadAll.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/LoadAll.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,7 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -56,13 +57,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArray.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArray.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArrayIntInt.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferByteArrayIntInt.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFile.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFile.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFileLongLong.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/NewModelByteBufferFileLongLong.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Available.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Available.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Close.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Close.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkReset.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkReset.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkSupported.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/MarkSupported.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Read.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Read.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByte.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByte.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByteIntInt.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/ReadByteIntInt.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Skip.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/RandomFileInputStream/Skip.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,8 +28,9 @@
 
 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.*;
 
@@ -55,13 +56,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLong.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLong.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLong.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLong.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLongBoolean.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/SubbufferLongLongBoolean.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,6 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -53,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Unload.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/Unload.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -28,7 +28,8 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -54,13 +55,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/WriteTo.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBuffer/WriteTo.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -29,7 +29,9 @@
 import java.io.ByteArrayOutputStream;
 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.*;
 
@@ -55,13 +57,13 @@
         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);
-        fos.write(test_byte_array);
+        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 {
--- a/jdk/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/OpenStream.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/midi/Gervill/ModelByteBufferWavetable/OpenStream.java	Tue Aug 23 20:45:35 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -30,6 +30,8 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.sound.sampled.*;
 
@@ -99,16 +101,15 @@
         buffer_wave = new ModelByteBuffer(baos.toByteArray());
 
         test_file = File.createTempFile("test", ".raw");
-        FileOutputStream fos = new FileOutputStream(test_file);
-        fos.write(baos.toByteArray());
-        fos.close();
+        try (FileOutputStream fos = new FileOutputStream(test_file)) {
+            fos.write(baos.toByteArray());
+        }
         buffer_wave_ondisk = new ModelByteBuffer(test_file);
 
     }
 
     static void tearDown() throws Exception {
-        if (!test_file.delete())
-            test_file.deleteOnExit();
+        Files.delete(Paths.get(test_file.getAbsolutePath()));
     }
 
     public static void testOpenStream(ModelByteBufferWavetable wavetable)
--- a/jdk/test/javax/sound/sampled/AudioInputStream/FrameLengthAfterConversion.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/sampled/AudioInputStream/FrameLengthAfterConversion.java	Tue Aug 23 20:45:35 2016 +0300
@@ -26,6 +26,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -162,7 +164,7 @@
             ais = AudioSystem.getAudioInputStream(temp);
             final long frameLength = ais.getFrameLength();
             ais.close();
-            temp.delete();
+            Files.delete(Paths.get(temp.getAbsolutePath()));
             validate(frameLength);
         } catch (IllegalArgumentException | UnsupportedAudioFileException
                 | IOException ignored) {
--- a/jdk/test/javax/sound/sampled/spi/AudioFileWriter/WriteUnsupportedAudioFormat.java	Tue Aug 23 18:15:27 2016 +0300
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileWriter/WriteUnsupportedAudioFormat.java	Tue Aug 23 20:45:35 2016 +0300
@@ -27,6 +27,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -91,7 +93,6 @@
         } catch (final IOException e) {
             throw new RuntimeException(e);
         }
-        FILE.deleteOnExit();
 
         for (final Boolean end : new boolean[]{false, true}) {
             for (final int sampleSize : sampleBits) {
@@ -134,6 +135,7 @@
                 }
             }
         }
+        Files.delete(Paths.get(FILE.getAbsolutePath()));
     }
 
     /**