8160217: JavaSound should clean up resources better

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2016-08-23 20:45:35 +03:00
parent 17cd11bc15
commit 201065a6ba
25 changed files with 173 additions and 133 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -200,11 +200,13 @@ public final class ModelByteBuffer {
public void writeTo(OutputStream out) throws IOException { public void writeTo(OutputStream out) throws IOException {
if (root.file != null && root.buffer == null) { if (root.file != null && root.buffer == null) {
InputStream is = getInputStream(); try (InputStream is = getInputStream()) {
byte[] buff = new byte[1024]; byte[] buff = new byte[1024];
int ret; int ret;
while ((ret = is.read(buff)) != -1) while ((ret = is.read(buff)) != -1) {
out.write(buff, 0, ret); out.write(buff, 0, ret);
}
}
} else } else
out.write(array(), (int) arrayOffset(), (int) capacity()); out.write(array(), (int) arrayOffset(), (int) capacity());
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; 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 javax.sound.sampled.*;
@ -54,13 +56,13 @@ public class GetInputStream {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -76,7 +78,9 @@ public class GetInputStream {
buff = new ModelByteBuffer(test_byte_array); buff = new ModelByteBuffer(test_byte_array);
byte[] b = new byte[test_byte_array.length]; 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++) for (int j = 0; j < b.length; j++)
if(b[i] != test_byte_array[i]) if(b[i] != test_byte_array[i])
throw new RuntimeException("Byte array compare fails!"); throw new RuntimeException("Byte array compare fails!");

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class GetRoot {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -54,13 +55,13 @@ public class Load {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; 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.ArrayList;
import java.util.List; import java.util.List;
@ -56,13 +57,13 @@ public class LoadAll {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class NewModelByteBufferByteArray {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class NewModelByteBufferByteArrayIntInt {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class NewModelByteBufferFile {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class NewModelByteBufferFileLongLong {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class Available {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class Close {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class MarkReset {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class MarkSupported {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class Read {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class ReadByte {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class ReadByteIntInt {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,9 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -55,13 +56,13 @@ public class Skip {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class SubbufferLong {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class SubbufferLongLong {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -53,13 +55,13 @@ public class SubbufferLongLongBoolean {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -54,13 +55,13 @@ public class Unload {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,7 +29,9 @@
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; 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 javax.sound.sampled.*;
@ -55,13 +57,13 @@ public class WriteTo {
test_byte_array = new byte[testarray.length*2]; test_byte_array = new byte[testarray.length*2];
AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array); AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(test_byte_array); fos.write(test_byte_array);
} }
}
static void tearDown() throws Exception { static void tearDown() throws Exception {
if(!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,8 @@
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.sound.sampled.*; import javax.sound.sampled.*;
@ -99,16 +101,15 @@ public class OpenStream {
buffer_wave = new ModelByteBuffer(baos.toByteArray()); buffer_wave = new ModelByteBuffer(baos.toByteArray());
test_file = File.createTempFile("test", ".raw"); test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file); try (FileOutputStream fos = new FileOutputStream(test_file)) {
fos.write(baos.toByteArray()); fos.write(baos.toByteArray());
fos.close(); }
buffer_wave_ondisk = new ModelByteBuffer(test_file); buffer_wave_ondisk = new ModelByteBuffer(test_file);
} }
static void tearDown() throws Exception { static void tearDown() throws Exception {
if (!test_file.delete()) Files.delete(Paths.get(test_file.getAbsolutePath()));
test_file.deleteOnExit();
} }
public static void testOpenStream(ModelByteBufferWavetable wavetable) public static void testOpenStream(ModelByteBufferWavetable wavetable)

View File

@ -26,6 +26,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -162,7 +164,7 @@ public final class FrameLengthAfterConversion {
ais = AudioSystem.getAudioInputStream(temp); ais = AudioSystem.getAudioInputStream(temp);
final long frameLength = ais.getFrameLength(); final long frameLength = ais.getFrameLength();
ais.close(); ais.close();
temp.delete(); Files.delete(Paths.get(temp.getAbsolutePath()));
validate(frameLength); validate(frameLength);
} catch (IllegalArgumentException | UnsupportedAudioFileException } catch (IllegalArgumentException | UnsupportedAudioFileException
| IOException ignored) { | IOException ignored) {

View File

@ -27,6 +27,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -91,7 +93,6 @@ public final class WriteUnsupportedAudioFormat {
} catch (final IOException e) { } catch (final IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
FILE.deleteOnExit();
for (final Boolean end : new boolean[]{false, true}) { for (final Boolean end : new boolean[]{false, true}) {
for (final int sampleSize : sampleBits) { for (final int sampleSize : sampleBits) {
@ -134,6 +135,7 @@ public final class WriteUnsupportedAudioFormat {
} }
} }
} }
Files.delete(Paths.get(FILE.getAbsolutePath()));
} }
/** /**