test/jdk/javax/sound/sampled/spi/AudioFileReader/AudioFileClose.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32121
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     1
/*
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     4
 *
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     8
 *
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    13
 * accompanied this code).
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    14
 *
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    18
 *
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    21
 * questions.
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    22
 */
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    23
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    24
import java.io.File;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    25
import java.io.FileOutputStream;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    26
import java.io.IOException;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    27
import java.io.InputStream;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    28
import java.io.OutputStream;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    29
import java.nio.file.Files;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    30
import java.nio.file.Paths;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    31
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    32
import javax.sound.sampled.AudioSystem;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    33
import javax.sound.sampled.UnsupportedAudioFileException;
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    34
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    35
/**
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    36
 * @test
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    37
 * @bug 8013586
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    38
 * @author Sergey Bylokhov
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    39
 */
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    40
public final class AudioFileClose {
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    41
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    42
    public static void main(final String[] args) throws Exception {
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    43
        final File file = Files.createTempFile("JavaSound", "Test").toFile();
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    44
        try (OutputStream fos = new FileOutputStream(file)) {
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    45
            fos.write(new byte[200]);
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    46
        }
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    47
        try {
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    48
            final InputStream stream = AudioSystem.getAudioInputStream(file);
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    49
            stream.close();
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    50
        } catch (final IOException | UnsupportedAudioFileException ignored) {
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    51
        }
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    52
        Files.delete(Paths.get(file.getAbsolutePath()));
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    53
    }
93ad23865c9e 8013586: audioInputStream.close() does not release the resource
serb
parents:
diff changeset
    54
}