8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
Summary: The specification change was reviewed by Florian Bomers also
Reviewed-by: amenkov
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AiffFileWriter.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AiffFileWriter.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -37,6 +37,7 @@
import java.io.ByteArrayOutputStream;
import java.io.RandomAccessFile;
import java.io.SequenceInputStream;
+import java.util.Objects;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
@@ -84,6 +85,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
//$$fb the following check must come first ! Otherwise
// the next frame length check may throw an IOException and
@@ -103,6 +107,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AlawCodec.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AlawCodec.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -26,6 +26,7 @@
package com.sun.media.sound;
import java.io.IOException;
+import java.util.Objects;
import java.util.Vector;
import javax.sound.sampled.AudioFormat;
@@ -119,6 +120,7 @@
/**
*/
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
+ Objects.requireNonNull(sourceFormat);
if( (targetEncoding.equals( AudioFormat.Encoding.PCM_SIGNED ) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.ALAW)) ||
(targetEncoding.equals( AudioFormat.Encoding.ALAW) && sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED)) ) {
return getOutputFormats( sourceFormat );
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AuFileWriter.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AuFileWriter.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -37,6 +37,7 @@
import java.io.ByteArrayOutputStream;
import java.io.RandomAccessFile;
import java.io.SequenceInputStream;
+import java.util.Objects;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
@@ -83,6 +84,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
// we must know the total data length to calculate the file length
//$$fb 2001-07-13: fix for bug 4351296: do not throw an exception
@@ -100,6 +104,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AudioFloatFormatConverter.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AudioFloatFormatConverter.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Objects;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@@ -538,6 +539,7 @@
public AudioFormat[] getTargetFormats(Encoding targetEncoding,
AudioFormat sourceFormat) {
+ Objects.requireNonNull(targetEncoding);
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return new AudioFormat[0];
int channels = sourceFormat.getChannels();
@@ -592,6 +594,7 @@
public boolean isConversionSupported(AudioFormat targetFormat,
AudioFormat sourceFormat) {
+ Objects.requireNonNull(targetFormat);
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return false;
if (AudioFloatConverter.getConverter(targetFormat) == null)
@@ -605,6 +608,7 @@
public boolean isConversionSupported(Encoding targetEncoding,
AudioFormat sourceFormat) {
+ Objects.requireNonNull(targetEncoding);
if (AudioFloatConverter.getConverter(sourceFormat) == null)
return false;
for (int i = 0; i < formats.length; i++) {
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDeviceProvider.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDeviceProvider.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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
@@ -121,7 +121,8 @@
}
}
}
- throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
+ throw new IllegalArgumentException(
+ String.format("Mixer %s not supported by this provider", info));
}
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/PCMtoPCMCodec.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/PCMtoPCMCodec.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -26,6 +26,7 @@
package com.sun.media.sound;
import java.io.IOException;
+import java.util.Objects;
import java.util.Vector;
import javax.sound.sampled.AudioFormat;
@@ -87,6 +88,7 @@
/**
*/
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
+ Objects.requireNonNull(targetEncoding);
// filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/PortMixerProvider.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/PortMixerProvider.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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
@@ -101,7 +101,6 @@
}
}
-
public Mixer getMixer(Mixer.Info info) {
synchronized (PortMixerProvider.class) {
for (int i = 0; i < infos.length; i++) {
@@ -110,8 +109,8 @@
}
}
}
- throw new IllegalArgumentException("Mixer " + info.toString()
- + " not supported by this provider.");
+ throw new IllegalArgumentException(
+ String.format("Mixer %s not supported by this provider", info));
}
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/UlawCodec.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/UlawCodec.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -27,6 +27,7 @@
import java.io.IOException;
+import java.util.Objects;
import java.util.Vector;
import javax.sound.sampled.AudioFormat;
@@ -106,6 +107,8 @@
/**
*/
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
+ Objects.requireNonNull(targetEncoding);
+ Objects.requireNonNull(sourceFormat);
if( (AudioFormat.Encoding.PCM_SIGNED.equals(targetEncoding)
&& AudioFormat.Encoding.ULAW.equals(sourceFormat.getEncoding()))
||
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/WaveFileWriter.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/WaveFileWriter.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -37,6 +37,7 @@
import java.io.ByteArrayOutputStream;
import java.io.RandomAccessFile;
import java.io.SequenceInputStream;
+import java.util.Objects;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
@@ -106,6 +107,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
//$$fb the following check must come first ! Otherwise
// the next frame length check may throw an IOException and
@@ -127,6 +131,9 @@
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);
--- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Sun Nov 22 17:27:33 2015 +0300
@@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
@@ -191,50 +192,21 @@
* mixer installed on the system
* @see #getMixerInfo
*/
- public static Mixer getMixer(Mixer.Info info) {
-
- Mixer mixer = null;
- List<MixerProvider> providers = getMixerProviders();
-
- for(int i = 0; i < providers.size(); i++ ) {
-
+ public static Mixer getMixer(final Mixer.Info info) {
+ for (final MixerProvider provider : getMixerProviders()) {
try {
- return providers.get(i).getMixer(info);
-
- } catch (IllegalArgumentException e) {
- } catch (NullPointerException e) {
- // $$jb 08.20.99: If the strings in the info object aren't
- // set, then Netscape (using jdk1.1.5) tends to throw
- // NPE's when doing some string manipulation. This is
- // probably not the best fix, but is solves the problem
- // of the NPE in Netscape using local classes
- // $$jb 11.01.99: Replacing this patch.
+ return provider.getMixer(info);
+ } catch (IllegalArgumentException | NullPointerException ignored) {
+ // The MixerProvider.getMixer(null) should return default Mixer,
+ // This behaviour was assumed from the beginning, but strictly
+ // specified only in the jdk9. Since the jdk1.1.5 we skipped
+ // NPE for some reason and therefore skipped some
+ // implementations of MixerProviders, which throw NPE. To keep
+ // support of such implementations, we still ignore NPE.
}
}
-
- //$$fb if looking for default mixer, and not found yet, add a round of looking
- if (info == null) {
- for(int i = 0; i < providers.size(); i++ ) {
- try {
- MixerProvider provider = providers.get(i);
- Mixer.Info[] infos = provider.getMixerInfo();
- // start from 0 to last device (do not reverse this order)
- for (int ii = 0; ii < infos.length; ii++) {
- try {
- return provider.getMixer(infos[ii]);
- } catch (IllegalArgumentException e) {
- // this is not a good default device :)
- }
- }
- } catch (IllegalArgumentException e) {
- } catch (NullPointerException e) {
- }
- }
- }
-
-
- throw new IllegalArgumentException("Mixer not supported: "
- + (info!=null?info.toString():"null"));
+ throw new IllegalArgumentException(
+ String.format("Mixer not supported: %s", info));
}
//$$fb 2002-11-26: fix for 4757930: DOC: AudioSystem.getTarget/SourceLineInfo() is ambiguous
@@ -696,8 +668,10 @@
* array of length 0 is returned. Otherwise, the array will have a
* length of at least 1, representing {@code sourceEncoding}
* (no conversion).
+ * @throws NullPointerException if {@code sourceEncoding} is {@code null}
*/
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {
+ Objects.requireNonNull(sourceEncoding);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
Vector<AudioFormat.Encoding> encodings = new Vector<>();
@@ -730,9 +704,10 @@
* array of length 0 is returned. Otherwise, the array will have a
* length of at least 1, representing the encoding of
* {@code sourceFormat} (no conversion).
+ * @throws NullPointerException if {@code sourceFormat} is {@code null}
*/
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
-
+ Objects.requireNonNull(sourceFormat);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
Vector<AudioFormat.Encoding[]> encodings = new Vector<>();
@@ -769,9 +744,12 @@
* @param sourceFormat the audio format before conversion
* @return {@code true} if the conversion is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceFormat} are {@code null}
*/
public static boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
-
+ Objects.requireNonNull(targetEncoding);
+ Objects.requireNonNull(sourceFormat);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
@@ -792,6 +770,8 @@
* @param sourceStream the stream to be converted
* @return an audio input stream of the indicated encoding
* @throws IllegalArgumentException if the conversion is not supported
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceStream} are {@code null}
* @see #getTargetEncodings(AudioFormat.Encoding)
* @see #getTargetEncodings(AudioFormat)
* @see #isConversionSupported(AudioFormat.Encoding, AudioFormat)
@@ -799,6 +779,8 @@
*/
public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
AudioInputStream sourceStream) {
+ Objects.requireNonNull(targetEncoding);
+ Objects.requireNonNull(sourceStream);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
@@ -821,8 +803,12 @@
* @param sourceFormat the audio format before conversion
* @return array of formats. If no formats of the specified encoding are
* supported, an array of length 0 is returned.
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceFormat} are {@code null}
*/
public static AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {
+ Objects.requireNonNull(targetEncoding);
+ Objects.requireNonNull(sourceFormat);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
Vector<AudioFormat[]> formats = new Vector<>();
@@ -860,8 +846,12 @@
* @param sourceFormat the audio format before conversion
* @return {@code true} if the conversion is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code targetFormat} or
+ * {@code sourceFormat} are {@code null}
*/
public static boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) {
+ Objects.requireNonNull(targetFormat);
+ Objects.requireNonNull(sourceFormat);
List<FormatConversionProvider> codecs = getFormatConversionProviders();
@@ -882,6 +872,8 @@
* @param sourceStream the stream to be converted
* @return an audio input stream of the indicated format
* @throws IllegalArgumentException if the conversion is not supported
+ * @throws NullPointerException if {@code targetFormat} or
+ * {@code sourceStream} are {@code null}
* @see #getTargetEncodings(AudioFormat)
* @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
* @see #isConversionSupported(AudioFormat, AudioFormat)
@@ -889,7 +881,6 @@
*/
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
AudioInputStream sourceStream) {
-
if (sourceStream.getFormat().matches(targetFormat)) {
return sourceStream;
}
@@ -924,11 +915,13 @@
* @throws UnsupportedAudioFileException if the stream does not point to
* valid audio file data recognized by the system
* @throws IOException if an input/output exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
public static AudioFileFormat getAudioFileFormat(InputStream stream)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(stream);
List<AudioFileReader> providers = getAudioFileReaders();
AudioFileFormat format = null;
@@ -961,9 +954,11 @@
* @throws UnsupportedAudioFileException if the URL does not point to valid
* audio file data recognized by the system
* @throws IOException if an input/output exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public static AudioFileFormat getAudioFileFormat(URL url)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(url);
List<AudioFileReader> providers = getAudioFileReaders();
AudioFileFormat format = null;
@@ -996,9 +991,11 @@
* @throws UnsupportedAudioFileException if the {@code File} does not point
* to valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public static AudioFileFormat getAudioFileFormat(File file)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(file);
List<AudioFileReader> providers = getAudioFileReaders();
AudioFileFormat format = null;
@@ -1037,11 +1034,13 @@
* @throws UnsupportedAudioFileException if the stream does not point to
* valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
public static AudioInputStream getAudioInputStream(InputStream stream)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(stream);
List<AudioFileReader> providers = getAudioFileReaders();
AudioInputStream audioStream = null;
@@ -1074,9 +1073,11 @@
* @throws UnsupportedAudioFileException if the URL does not point to valid
* audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public static AudioInputStream getAudioInputStream(URL url)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(url);
List<AudioFileReader> providers = getAudioFileReaders();
AudioInputStream audioStream = null;
@@ -1109,9 +1110,11 @@
* @throws UnsupportedAudioFileException if the {@code File} does not point
* to valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public static AudioInputStream getAudioInputStream(File file)
- throws UnsupportedAudioFileException, IOException {
+ throws UnsupportedAudioFileException, IOException {
+ Objects.requireNonNull(file);
List<AudioFileReader> providers = getAudioFileReaders();
AudioInputStream audioStream = null;
@@ -1163,9 +1166,10 @@
* @param fileType the file type for which write capabilities are queried
* @return {@code true} if the file type is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code fileType} is {@code null}
*/
public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
-
+ Objects.requireNonNull(fileType);
List<AudioFileWriter> providers = getAudioFileWriters();
for(int i=0; i < providers.size(); i++) {
@@ -1185,8 +1189,10 @@
* support is queried
* @return array of file types. If no file types are supported, an array of
* length 0 is returned.
+ * @throws NullPointerException if {@code stream} is {@code null}
*/
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
+ Objects.requireNonNull(stream);
List<AudioFileWriter> providers = getAudioFileWriters();
Set<AudioFileFormat.Type> returnTypesSet = new HashSet<>();
@@ -1210,10 +1216,13 @@
* @param stream the stream for which file-writing support is queried
* @return {@code true} if the file type is supported for this audio input
* stream, otherwise {@code false}
+ * @throws NullPointerException if {@code fileType} or {@code stream} are
+ * {@code null}
*/
public static boolean isFileTypeSupported(AudioFileFormat.Type fileType,
AudioInputStream stream) {
-
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(stream);
List<AudioFileWriter> providers = getAudioFileWriters();
for(int i=0; i < providers.size(); i++) {
@@ -1241,11 +1250,16 @@
* @throws IOException if an input/output exception occurs
* @throws IllegalArgumentException if the file type is not supported by the
* system
+ * @throws NullPointerException if {@code stream} or {@code fileType} or
+ * {@code out} are {@code null}
* @see #isFileTypeSupported
* @see #getAudioFileTypes
*/
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
OutputStream out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
List<AudioFileWriter> providers = getAudioFileWriters();
int bytesWritten = 0;
@@ -1281,11 +1295,16 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by the
* system
+ * @throws NullPointerException if {@code stream} or {@code fileType} or
+ * {@code out} are {@code null}
* @see #isFileTypeSupported
* @see #getAudioFileTypes
*/
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
File out) throws IOException {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
List<AudioFileWriter> providers = getAudioFileWriters();
int bytesWritten = 0;
--- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Sun Nov 22 17:27:33 2015 +0300
@@ -60,6 +60,7 @@
* @throws UnsupportedAudioFileException if the stream does not point to
* valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
@@ -77,6 +78,7 @@
* @throws UnsupportedAudioFileException if the URL does not point to valid
* audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public abstract AudioFileFormat getAudioFileFormat(URL url)
throws UnsupportedAudioFileException, IOException;
@@ -92,6 +94,7 @@
* @throws UnsupportedAudioFileException if the {@code File} does not point
* to valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public abstract AudioFileFormat getAudioFileFormat(File file)
throws UnsupportedAudioFileException, IOException;
@@ -112,6 +115,7 @@
* @throws UnsupportedAudioFileException if the stream does not point to
* valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
@@ -129,6 +133,7 @@
* @throws UnsupportedAudioFileException if the URL does not point to valid
* audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public abstract AudioInputStream getAudioInputStream(URL url)
throws UnsupportedAudioFileException, IOException;
@@ -144,6 +149,7 @@
* @throws UnsupportedAudioFileException if the {@code File} does not point
* to valid audio file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public abstract AudioInputStream getAudioInputStream(File file)
throws UnsupportedAudioFileException, IOException;
--- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Objects;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -60,8 +61,10 @@
* @param fileType the file type for which write capabilities are queried
* @return {@code true} if the file type is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code fileType} is {@code null}
*/
public boolean isFileTypeSupported(Type fileType) {
+ Objects.requireNonNull(fileType);
Type types[] = getAudioFileTypes();
@@ -81,6 +84,7 @@
* is queried
* @return array of file types. If no file types are supported, an array of
* length 0 is returned.
+ * @throws NullPointerException if {@code stream} is {@code null}
*/
public abstract Type[] getAudioFileTypes(AudioInputStream stream);
@@ -92,9 +96,11 @@
* @param stream for which file writing support is queried
* @return {@code true} if the file type is supported for this audio input
* stream, otherwise {@code false}
+ * @throws NullPointerException if {@code fileType} or {@code stream} are
+ * {@code null}
*/
public boolean isFileTypeSupported(Type fileType, AudioInputStream stream) {
-
+ Objects.requireNonNull(fileType);
Type types[] = getAudioFileTypes( stream );
for(int i=0; i<types.length; i++) {
@@ -121,6 +127,8 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by the
* system
+ * @throws NullPointerException if {@code stream} or {@code fileType} or
+ * {@code out} are {@code null}
* @see #isFileTypeSupported(AudioFileFormat.Type, AudioInputStream)
* @see #getAudioFileTypes
*/
@@ -139,6 +147,8 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file format is not supported by
* the system
+ * @throws NullPointerException if {@code stream} or {@code fileType} or
+ * {@code out} are {@code null}
* @see #isFileTypeSupported
* @see #getAudioFileTypes
*/
--- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -25,6 +25,8 @@
package javax.sound.sampled.spi;
+import java.util.Objects;
+
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@@ -77,9 +79,10 @@
* queried
* @return {@code true} if the encoding is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code sourceEncoding} is {@code null}
*/
public boolean isSourceEncodingSupported(Encoding sourceEncoding) {
-
+ Objects.requireNonNull(sourceEncoding);
Encoding sourceEncodings[] = getSourceEncodings();
for(int i=0; i<sourceEncodings.length; i++) {
@@ -98,9 +101,10 @@
* queried
* @return {@code true} if the encoding is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code targetEncoding} is {@code null}
*/
public boolean isTargetEncodingSupported(Encoding targetEncoding) {
-
+ Objects.requireNonNull(targetEncoding);
Encoding targetEncodings[] = getTargetEncodings();
for(int i=0; i<targetEncodings.length; i++) {
@@ -118,6 +122,7 @@
*
* @param sourceFormat format of the incoming data
* @return array of supported target format encodings
+ * @throws NullPointerException if {@code sourceFormat} is {@code null}
*/
public abstract Encoding[] getTargetEncodings(AudioFormat sourceFormat);
@@ -129,10 +134,12 @@
* @param sourceFormat format of the incoming data
* @return {@code true} if the conversion is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceFormat} are {@code null}
*/
public boolean isConversionSupported(Encoding targetEncoding,
AudioFormat sourceFormat) {
-
+ Objects.requireNonNull(targetEncoding);
Encoding targetEncodings[] = getTargetEncodings(sourceFormat);
for(int i=0; i<targetEncodings.length; i++) {
@@ -145,12 +152,14 @@
/**
* Obtains the set of target formats with the encoding specified supported
- * by the format converter If no target formats with the specified encoding
+ * by the format converter. If no target formats with the specified encoding
* are supported for this source format, an array of length 0 is returned.
*
* @param targetEncoding desired encoding of the stream after processing
* @param sourceFormat format of the incoming data
* @return array of supported target formats
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceFormat} are {@code null}
*/
public abstract AudioFormat[] getTargetFormats(Encoding targetEncoding,
AudioFormat sourceFormat);
@@ -163,6 +172,8 @@
* @param sourceFormat format of the incoming data
* @return {@code true} if the conversion is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code targetFormat} or
+ * {@code sourceFormat} are {@code null}
*/
public boolean isConversionSupported(AudioFormat targetFormat,
AudioFormat sourceFormat) {
@@ -188,6 +199,8 @@
* encoding may be read
* @throws IllegalArgumentException if the format combination supplied is
* not supported
+ * @throws NullPointerException if {@code targetEncoding} or
+ * {@code sourceStream} are {@code null}
*/
public abstract AudioInputStream getAudioInputStream(
Encoding targetEncoding, AudioInputStream sourceStream);
@@ -203,6 +216,8 @@
* read
* @throws IllegalArgumentException if the format combination supplied is
* not supported
+ * @throws NullPointerException if {@code targetFormat} or
+ * {@code sourceStream} are {@code null}
*/
public abstract AudioInputStream getAudioInputStream(
AudioFormat targetFormat, AudioInputStream sourceStream);
--- a/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java Fri Nov 20 17:54:58 2015 -0600
+++ b/jdk/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java Sun Nov 22 17:27:33 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -25,6 +25,8 @@
package javax.sound.sampled.spi;
+import java.util.Objects;
+
import javax.sound.sampled.Mixer;
/**
@@ -49,9 +51,11 @@
* queried
* @return {@code true} if the specified mixer is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code info} is {@code null}
* @see #getMixerInfo()
*/
public boolean isMixerSupported(Mixer.Info info) {
+ Objects.requireNonNull(info);
Mixer.Info infos[] = getMixerInfo();
@@ -78,17 +82,21 @@
public abstract Mixer.Info[] getMixerInfo();
/**
- * Obtains an instance of the mixer represented by the info object.
+ * Obtains an instance of the mixer represented by the info object. If
+ * {@code null} is passed, then the default mixer will be returned.
* <p>
* The full set of the mixer info objects that represent the mixers
* supported by this {@code MixerProvider} may be obtained through the
* {@code getMixerInfo} method. Use the {@code isMixerSupported} method to
* test whether this {@code MixerProvider} supports a particular mixer.
*
- * @param info an info object that describes the desired mixer
+ * @param info an info object that describes the desired mixer, or
+ * {@code null} for the default mixer
* @return mixer instance
* @throws IllegalArgumentException if the info object specified does not
- * match the info object for a mixer supported by this MixerProvider
+ * match the info object for a mixer supported by this
+ * {@code MixerProvider}, or if this {@code MixerProvider} does not
+ * have default mixer, but default mixer has been requested
* @see #getMixerInfo()
* @see #isMixerSupported(Mixer.Info)
*/
--- a/jdk/test/javax/sound/sampled/FileReader/AudioFileClose.java Fri Nov 20 17:54:58 2015 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.UnsupportedAudioFileException;
-
-/**
- * @test
- * @bug 8013586
- * @author Sergey Bylokhov
- */
-public final class AudioFileClose {
-
- public static void main(final String[] args) throws Exception {
- final File file = Files.createTempFile("JavaSound", "Test").toFile();
- try (OutputStream fos = new FileOutputStream(file)) {
- fos.write(new byte[200]);
- }
- try {
- final InputStream stream = AudioSystem.getAudioInputStream(file);
- stream.close();
- } catch (final IOException | UnsupportedAudioFileException ignored) {
- }
- Files.delete(Paths.get(file.getAbsolutePath()));
- }
-}
--- a/jdk/test/javax/sound/sampled/FileReader/ReadersExceptions.java Fri Nov 20 17:54:58 2015 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2013, 2015, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.UnsupportedAudioFileException;
-import javax.sound.sampled.spi.AudioFileReader;
-
-import static java.util.ServiceLoader.load;
-
-/**
- * @test
- * @bug 7058662 7058666 7058672 8130305
- * @author Sergey Bylokhov
- */
-public final class ReadersExceptions {
-
- // empty channels
- static byte[] wrongAIFFCh =
- {0x46, 0x4f, 0x52, 0x4d, // AiffFileFormat.AIFF_MAGIC
- 0, 0, 0, 0, // length
- 0, 0, 0, 0, // iffType
- 0x43, 0x4f, 0x4d, 0x4d, // chunkName
- 0, 0, 0, 100, // chunkLen
- 0, 0, // channels
- 0, 0, 0, 0, //
- 0, 10 // sampleSize
- , 0, 0, 0, 0};
- // empty sampleSize
- static byte[] wrongAIFFSSL =
- {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
- 0, 0, 0, 0, // length
- 0, 0, 0, 0, // iffType
- 0x43, 0x4f, 0x4d, 0x4d, // chunkName
- 0, 0, 0, 100, // chunkLen
- 0, 10, // channels
- 0, 0, 0, 0, //
- 0, 0 // sampleSize
- , 0, 0, 0, 0};
- // big sampleSize
- static byte[] wrongAIFFSSH =
- {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
- 0, 0, 0, 0, // length
- 0, 0, 0, 0, // iffType
- 0x43, 0x4f, 0x4d, 0x4d, // chunkName
- 0, 0, 0, 100, // chunkLen
- 0, 10, // channels
- 0, 0, 0, 0, //
- 0, 33 // sampleSize
- , 0, 0, 0, 0};
- // empty channels
- static byte[] wrongAUCh =
- {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
- 0, 0, 0, 0, // headerSize
- 0, 0, 0, 0, // dataSize
- 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
- 0, 0, 0, 0, // sampleRate
- 0, 0, 0, 0 // channels
- };
- // empty channels
- static byte[] wrongWAVCh =
- {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
- 1, 1, 1, 1, // fileLength
- 0x57, 0x41, 0x56, 0x45, // waveMagic
- 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
- 3, 0, 0, 0, // length
- 1, 0, // wav_type WAVE_FORMAT_PCM
- 0, 0, // channels
- 0, 0, 0, 0, // sampleRate
- 0, 0, 0, 0, // avgBytesPerSec
- 0, 0, // blockAlign
- 1, 0, // sampleSizeInBits
- 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
- 0, 0, 0, 0, // dataLength
- };
- // empty sampleSizeInBits
- static byte[] wrongWAVSSB =
- {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
- 1, 1, 1, 1, // fileLength
- 0x57, 0x41, 0x56, 0x45, // waveMagic
- 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
- 3, 0, 0, 0, // length
- 1, 0, // wav_type WAVE_FORMAT_PCM
- 1, 0, // channels
- 0, 0, 0, 0, // sampleRate
- 0, 0, 0, 0, // avgBytesPerSec
- 0, 0, // blockAlign
- 0, 0, // sampleSizeInBits
- 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
- 0, 0, 0, 0, // dataLength
- };
-
- static byte[][] data = {wrongAIFFCh, wrongAIFFSSL, wrongAIFFSSH, wrongAUCh,
- wrongWAVCh, wrongWAVSSB};
-
- public static void main(final String[] args) throws IOException {
- for (final byte[] bytes : data) {
- testAS(bytes);
- testAFR(bytes);
- }
- }
-
- private static void testAS(final byte[] buffer) throws IOException {
- // AudioSystem API
- final InputStream is = new ByteArrayInputStream(buffer);
- try {
- AudioSystem.getAudioFileFormat(is);
- } catch (UnsupportedAudioFileException ignored) {
- // Expected.
- return;
- }
- throw new RuntimeException("Test Failed");
- }
-
- private static void testAFR(final byte[] buffer) throws IOException {
- // AudioFileReader API
- final InputStream is = new ByteArrayInputStream(buffer);
- for (final AudioFileReader afr : load(AudioFileReader.class)) {
- for (int i = 0; i < 10; ++i) {
- try {
- afr.getAudioFileFormat(is);
- throw new RuntimeException("UAFE expected");
- } catch (final UnsupportedAudioFileException ignored) {
- // Expected.
- }
- }
- }
- }
-}
--- a/jdk/test/javax/sound/sampled/FileReader/RepeatedFormatReader.java Fri Nov 20 17:54:58 2015 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.UnsupportedAudioFileException;
-
-/**
- * @test
- * @bug 8133677
- * @summary Subsequent read from the same stream should work
- */
-public final class RepeatedFormatReader {
-
- // Stubs
-
- private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd
- 0, 0, 0, 6, // read header length
- 0, 0, // type
- 0, 0, // numtracks
- 0, 1, // timing
- };
-
- private static byte[] headerAU = {0x2e, 0x73, 0x6e, 0x64, // AU_SUN_MAGIC
- 0, 0, 0, 0, // headerSize
- 0, 0, 0, 0, // dataSize
- 0, 0, 0, 1, // encoding
- 0, 0, 0, 0, // sampleRate
- 0, 0, 0, 1 // channels
- };
-
- private static byte[] headerWAV = {0x52, 0x49, 0x46, 0x46, // RIFF_MAGIC
- 1, 1, 1, 1, // fileLength
- 0x57, 0x41, 0x56, 0x45, // waveMagic
- 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
- 3, 0, 0, 0, // length
- 1, 0, // wav_type WAVE_FORMAT_PCM
- 0, 1, // channels
- 0, 0, 0, 0, // sampleRate
- 0, 0, 0, 0, // avgBytesPerSec
- 0, 0, // blockAlign
- 1, 0, // sampleSizeInBits
- 0x64, 0x61, 0x74, 0x61, // DATA_MAGIC
- 0, 0, 0, 0, // dataLength
- };
-
- private static final byte[][] data = {headerMIDI, headerAU, headerWAV};
-
- public static void main(final String[] args)
- throws IOException, UnsupportedAudioFileException {
- for (final byte[] bytes : data) {
- test(bytes);
- }
- }
-
- private static void test(final byte[] buffer)
- throws IOException, UnsupportedAudioFileException {
- final InputStream is = new ByteArrayInputStream(buffer);
- for (int i = 0; i < 10; ++i) {
- AudioSystem.getAudioFileFormat(is);
- }
- }
-}
--- a/jdk/test/javax/sound/sampled/FileWriter/AlawEncoderSync.java Fri Nov 20 17:54:58 2015 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @bug 6938426
- * @bug 7058852
- * @summary Tests that Alaw encoder works properly in multithreaded environment
- * @author Alex Menkov
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.util.Arrays;
-import javax.sound.sampled.AudioFormat;
-import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
-
-public class AlawEncoderSync {
-
- static final int THREAD_COUNT = 20;
-
- static final AudioFormat pcmFormat = new AudioFormat(8000f, 16, 2, true, false);
- static final int STREAM_LENGTH = 10; // in seconds
- static byte[] pcmBuffer;
- static final AudioFormat alawFormat
- = new AudioFormat(AudioFormat.Encoding.ALAW, 8000f, 8, 2, 2, 8000f, false);
-
- static final ConversionThread[] threads = new ConversionThread[THREAD_COUNT];
-
- public static void main(String[] args) {
- preparePCMBuffer();
- log("pcmStream size: " + pcmBuffer.length);
-
- for (int i=0; i<THREAD_COUNT; i++) {
- threads[i] = new ConversionThread(i);
- threads[i].start();
- }
-
- for (int i=0; i<THREAD_COUNT; i++) {
- try {
- threads[i].join();
- } catch (InterruptedException ex) {
- log("Main thread was interrupted, exiting.");
- return;
- }
- }
-
- int failed = 0;
- log("comparing result arrays...");
- for (int i=1; i<THREAD_COUNT; i++) {
- if (!Arrays.equals(threads[0].resultArray, threads[i].resultArray)) {
- failed++;
- log("NOT equals: 0 and " + i);
- }
- }
- if (failed > 0) {
- throw new RuntimeException("test FAILED");
- }
- log("test PASSED.");
- }
-
-
- static void preparePCMBuffer() {
- pcmBuffer = new byte[STREAM_LENGTH * (int)pcmFormat.getSampleRate()
- * (pcmFormat.getSampleSizeInBits() / 8) * pcmFormat.getChannels()];
- for (int i=0; i<pcmBuffer.length; i++) {
- pcmBuffer[i] = (byte)(Math.random() * 256.0 - 128.0);
- }
- }
-
- static AudioInputStream createPCMStream() {
- InputStream byteStream = new ByteArrayInputStream(pcmBuffer);
- return new AudioInputStream(byteStream, pcmFormat, AudioSystem.NOT_SPECIFIED);
- }
-
- static class ConversionThread extends Thread {
- public final int num;
- public byte[] resultArray = null;
- public ConversionThread(int num) {
- this.num = num;
- }
- @Override
- public void run() {
- log("ConversionThread[" + num + "] started.");
- try {
- InputStream inStream = new ByteArrayInputStream(pcmBuffer);
-
- AudioInputStream pcmStream = new AudioInputStream(
- inStream, pcmFormat, AudioSystem.NOT_SPECIFIED);
- AudioInputStream alawStream = AudioSystem.getAudioInputStream(alawFormat, pcmStream);
-
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- int read = 0;
- byte[] data = new byte[4096];
- while((read = alawStream.read(data)) != -1) {
- outStream.write(data, 0, read);
- }
- alawStream.close();
- resultArray = outStream.toByteArray();
- } catch (Exception ex) {
- log("ConversionThread[" + num + "] exception:");
- log(ex);
- }
- log("ConversionThread[" + num + "] completed.");
- }
- }
-
- static void log(String s) {
- System.out.println(s);
- }
-
- static void log(Exception ex) {
- ex.printStackTrace(System.out);
- }
-}
--- a/jdk/test/javax/sound/sampled/FileWriter/WriterCloseInput.java Fri Nov 20 17:54:58 2015 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/**
- * @test
- * @bug 7013521
- * @summary AIFF/AU/WAVE writers close input audio stream
- * @author Alex Menkov
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import javax.sound.sampled.AudioFileFormat;
-import javax.sound.sampled.AudioFormat;
-import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
-
-
-public class WriterCloseInput {
-
- final static AudioFormat audioFormat = new AudioFormat(44100f, 16, 2, true, true);
- //final static AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 44100f, 8, 2, 2, 44100f, true);
- final static int frameLength = 44100 * 2; // 2 seconds
- final static byte[] dataBuffer
- = new byte[frameLength * (audioFormat.getSampleSizeInBits()/8)
- * audioFormat.getChannels()];
-
- static int testTotal = 0;
- static int testFailed = 0;
-
- public static void main(String[] args) throws Exception {
- test(AudioFileFormat.Type.AIFF);
- test(AudioFileFormat.Type.AU);
- test(AudioFileFormat.Type.WAVE);
-
- if (testFailed == 0) {
- out("All tests passed.");
- } else {
- out("" + testFailed + " of " + testTotal + " tests FAILED.");
- System.out.flush();
- throw new RuntimeException("Test FAILED.");
- }
- }
-
- static void test(AudioFileFormat.Type fileType) {
- test(fileType, frameLength);
- test(fileType, AudioSystem.NOT_SPECIFIED);
- }
-
- static void test(AudioFileFormat.Type fileType, int length) {
- test(fileType, length, false);
- test(fileType, length, true);
- }
-
- static void test(AudioFileFormat.Type fileType, int length, boolean isFile) {
- testTotal++;
- out("Testing fileType: " + fileType
- + ", frameLength: " + (length >= 0 ? length : "unspecified")
- + ", output: " + (isFile ? "File" : "OutputStream"));
- AudioInputStream inStream = new ThrowAfterCloseStream(
- new ByteArrayInputStream(dataBuffer), audioFormat, length);
-
- AudioSystem.isFileTypeSupported(fileType, inStream);
-
- try {
- if (isFile) {
- File f = File.createTempFile("WriterCloseInput" + testTotal, "tmp");
- AudioSystem.write(inStream, fileType, f);
- f.delete();
- } else {
- OutputStream outStream = new NullOutputStream();
- AudioSystem.write(inStream, fileType, outStream);
- }
- } catch (Exception ex) {
- // this is not failure
- out("SKIPPED (AudioSystem.write exception): " + ex.getMessage());
- //out(ex);
- inStream = null;
- }
-
- if (inStream != null) {
- try {
- // test if the stream is closed
- inStream.available();
- out("PASSED");
- } catch (IOException ex) {
- testFailed++;
- out("FAILED: " + ex.getMessage());
- //out(ex);
- }
- }
- out("");
- }
-
- static class ThrowAfterCloseStream extends AudioInputStream {
- private boolean closed = false;
- public ThrowAfterCloseStream(InputStream in, AudioFormat format, long length) {
- super(in, format, length);
- }
- @Override
- public void close() {
- closed = true;
- }
- @Override
- public int available() throws IOException {
- if (closed) {
- throw new IOException("The stream has been closed");
- }
- return 1;
- }
- }
-
- static class NullOutputStream extends OutputStream {
- @Override
- public void write(int b) throws IOException {
- // nop
- }
- }
-
- static void out(String s) {
- System.out.println(s);
- }
-
- static void out(Exception ex) {
- ex.printStackTrace(System.out);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileReader/AudioFileClose.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.UnsupportedAudioFileException;
+
+/**
+ * @test
+ * @bug 8013586
+ * @author Sergey Bylokhov
+ */
+public final class AudioFileClose {
+
+ public static void main(final String[] args) throws Exception {
+ final File file = Files.createTempFile("JavaSound", "Test").toFile();
+ try (OutputStream fos = new FileOutputStream(file)) {
+ fos.write(new byte[200]);
+ }
+ try {
+ final InputStream stream = AudioSystem.getAudioInputStream(file);
+ stream.close();
+ } catch (final IOException | UnsupportedAudioFileException ignored) {
+ }
+ Files.delete(Paths.get(file.getAbsolutePath()));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileReader/ExpectedNPEOnNull.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.spi.AudioFileReader;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8135100
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testAS();
+ testAFR();
+ }
+
+ /**
+ * Tests the part of AudioSystem API, which implemented via AudioFileReader.
+ */
+ private static void testAS() throws Exception {
+
+ try {
+ AudioSystem.getAudioFileFormat((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ AudioSystem.getAudioFileFormat((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ AudioSystem.getAudioFileFormat((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ AudioSystem.getAudioInputStream((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ AudioSystem.getAudioInputStream((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ AudioSystem.getAudioInputStream((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ /**
+ * Tests the AudioFileReader API directly.
+ */
+ private static void testAFR() throws Exception {
+
+ for (final AudioFileReader afr : load(AudioFileReader.class)) {
+ try {
+ afr.getAudioFileFormat((InputStream) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ afr.getAudioFileFormat((URL) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ afr.getAudioFileFormat((File) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ afr.getAudioInputStream((InputStream) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ afr.getAudioInputStream((URL) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ try {
+ afr.getAudioInputStream((File) null);
+ throw new RuntimeException("NPE is expected: " + afr);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileReader/ReadersExceptions.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2013, 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.UnsupportedAudioFileException;
+import javax.sound.sampled.spi.AudioFileReader;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 7058662 7058666 7058672 8130305
+ * @author Sergey Bylokhov
+ */
+public final class ReadersExceptions {
+
+ // empty channels
+ static byte[] wrongAIFFCh =
+ {0x46, 0x4f, 0x52, 0x4d, // AiffFileFormat.AIFF_MAGIC
+ 0, 0, 0, 0, // length
+ 0, 0, 0, 0, // iffType
+ 0x43, 0x4f, 0x4d, 0x4d, // chunkName
+ 0, 0, 0, 100, // chunkLen
+ 0, 0, // channels
+ 0, 0, 0, 0, //
+ 0, 10 // sampleSize
+ , 0, 0, 0, 0};
+ // empty sampleSize
+ static byte[] wrongAIFFSSL =
+ {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
+ 0, 0, 0, 0, // length
+ 0, 0, 0, 0, // iffType
+ 0x43, 0x4f, 0x4d, 0x4d, // chunkName
+ 0, 0, 0, 100, // chunkLen
+ 0, 10, // channels
+ 0, 0, 0, 0, //
+ 0, 0 // sampleSize
+ , 0, 0, 0, 0};
+ // big sampleSize
+ static byte[] wrongAIFFSSH =
+ {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
+ 0, 0, 0, 0, // length
+ 0, 0, 0, 0, // iffType
+ 0x43, 0x4f, 0x4d, 0x4d, // chunkName
+ 0, 0, 0, 100, // chunkLen
+ 0, 10, // channels
+ 0, 0, 0, 0, //
+ 0, 33 // sampleSize
+ , 0, 0, 0, 0};
+ // empty channels
+ static byte[] wrongAUCh =
+ {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
+ 0, 0, 0, 0, // headerSize
+ 0, 0, 0, 0, // dataSize
+ 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
+ 0, 0, 0, 0, // sampleRate
+ 0, 0, 0, 0 // channels
+ };
+ // empty channels
+ static byte[] wrongWAVCh =
+ {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
+ 1, 1, 1, 1, // fileLength
+ 0x57, 0x41, 0x56, 0x45, // waveMagic
+ 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
+ 3, 0, 0, 0, // length
+ 1, 0, // wav_type WAVE_FORMAT_PCM
+ 0, 0, // channels
+ 0, 0, 0, 0, // sampleRate
+ 0, 0, 0, 0, // avgBytesPerSec
+ 0, 0, // blockAlign
+ 1, 0, // sampleSizeInBits
+ 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
+ 0, 0, 0, 0, // dataLength
+ };
+ // empty sampleSizeInBits
+ static byte[] wrongWAVSSB =
+ {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
+ 1, 1, 1, 1, // fileLength
+ 0x57, 0x41, 0x56, 0x45, // waveMagic
+ 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
+ 3, 0, 0, 0, // length
+ 1, 0, // wav_type WAVE_FORMAT_PCM
+ 1, 0, // channels
+ 0, 0, 0, 0, // sampleRate
+ 0, 0, 0, 0, // avgBytesPerSec
+ 0, 0, // blockAlign
+ 0, 0, // sampleSizeInBits
+ 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
+ 0, 0, 0, 0, // dataLength
+ };
+
+ static byte[][] data = {wrongAIFFCh, wrongAIFFSSL, wrongAIFFSSH, wrongAUCh,
+ wrongWAVCh, wrongWAVSSB};
+
+ public static void main(final String[] args) throws IOException {
+ for (final byte[] bytes : data) {
+ testAS(bytes);
+ testAFR(bytes);
+ }
+ }
+
+ private static void testAS(final byte[] buffer) throws IOException {
+ // AudioSystem API
+ final InputStream is = new ByteArrayInputStream(buffer);
+ try {
+ AudioSystem.getAudioFileFormat(is);
+ } catch (UnsupportedAudioFileException ignored) {
+ // Expected.
+ return;
+ }
+ throw new RuntimeException("Test Failed");
+ }
+
+ private static void testAFR(final byte[] buffer) throws IOException {
+ // AudioFileReader API
+ final InputStream is = new ByteArrayInputStream(buffer);
+ for (final AudioFileReader afr : load(AudioFileReader.class)) {
+ for (int i = 0; i < 10; ++i) {
+ try {
+ afr.getAudioFileFormat(is);
+ throw new RuntimeException("UAFE expected");
+ } catch (final UnsupportedAudioFileException ignored) {
+ // Expected.
+ }
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileReader/RepeatedFormatReader.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.UnsupportedAudioFileException;
+
+/**
+ * @test
+ * @bug 8133677
+ * @summary Subsequent read from the same stream should work
+ */
+public final class RepeatedFormatReader {
+
+ // Stubs
+
+ private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd
+ 0, 0, 0, 6, // read header length
+ 0, 0, // type
+ 0, 0, // numtracks
+ 0, 1, // timing
+ };
+
+ private static byte[] headerAU = {0x2e, 0x73, 0x6e, 0x64, // AU_SUN_MAGIC
+ 0, 0, 0, 0, // headerSize
+ 0, 0, 0, 0, // dataSize
+ 0, 0, 0, 1, // encoding
+ 0, 0, 0, 0, // sampleRate
+ 0, 0, 0, 1 // channels
+ };
+
+ private static byte[] headerWAV = {0x52, 0x49, 0x46, 0x46, // RIFF_MAGIC
+ 1, 1, 1, 1, // fileLength
+ 0x57, 0x41, 0x56, 0x45, // waveMagic
+ 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
+ 3, 0, 0, 0, // length
+ 1, 0, // wav_type WAVE_FORMAT_PCM
+ 0, 1, // channels
+ 0, 0, 0, 0, // sampleRate
+ 0, 0, 0, 0, // avgBytesPerSec
+ 0, 0, // blockAlign
+ 1, 0, // sampleSizeInBits
+ 0x64, 0x61, 0x74, 0x61, // DATA_MAGIC
+ 0, 0, 0, 0, // dataLength
+ };
+
+ private static final byte[][] data = {headerMIDI, headerAU, headerWAV};
+
+ public static void main(final String[] args)
+ throws IOException, UnsupportedAudioFileException {
+ for (final byte[] bytes : data) {
+ test(bytes);
+ }
+ }
+
+ private static void test(final byte[] buffer)
+ throws IOException, UnsupportedAudioFileException {
+ final InputStream is = new ByteArrayInputStream(buffer);
+ for (int i = 0; i < 10; ++i) {
+ AudioSystem.getAudioFileFormat(is);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileWriter/AlawEncoderSync.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2010, 2013, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 6938426
+ * @bug 7058852
+ * @summary Tests that Alaw encoder works properly in multithreaded environment
+ * @author Alex Menkov
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+
+public class AlawEncoderSync {
+
+ static final int THREAD_COUNT = 20;
+
+ static final AudioFormat pcmFormat = new AudioFormat(8000f, 16, 2, true, false);
+ static final int STREAM_LENGTH = 10; // in seconds
+ static byte[] pcmBuffer;
+ static final AudioFormat alawFormat
+ = new AudioFormat(AudioFormat.Encoding.ALAW, 8000f, 8, 2, 2, 8000f, false);
+
+ static final ConversionThread[] threads = new ConversionThread[THREAD_COUNT];
+
+ public static void main(String[] args) {
+ preparePCMBuffer();
+ log("pcmStream size: " + pcmBuffer.length);
+
+ for (int i=0; i<THREAD_COUNT; i++) {
+ threads[i] = new ConversionThread(i);
+ threads[i].start();
+ }
+
+ for (int i=0; i<THREAD_COUNT; i++) {
+ try {
+ threads[i].join();
+ } catch (InterruptedException ex) {
+ log("Main thread was interrupted, exiting.");
+ return;
+ }
+ }
+
+ int failed = 0;
+ log("comparing result arrays...");
+ for (int i=1; i<THREAD_COUNT; i++) {
+ if (!Arrays.equals(threads[0].resultArray, threads[i].resultArray)) {
+ failed++;
+ log("NOT equals: 0 and " + i);
+ }
+ }
+ if (failed > 0) {
+ throw new RuntimeException("test FAILED");
+ }
+ log("test PASSED.");
+ }
+
+
+ static void preparePCMBuffer() {
+ pcmBuffer = new byte[STREAM_LENGTH * (int)pcmFormat.getSampleRate()
+ * (pcmFormat.getSampleSizeInBits() / 8) * pcmFormat.getChannels()];
+ for (int i=0; i<pcmBuffer.length; i++) {
+ pcmBuffer[i] = (byte)(Math.random() * 256.0 - 128.0);
+ }
+ }
+
+ static AudioInputStream createPCMStream() {
+ InputStream byteStream = new ByteArrayInputStream(pcmBuffer);
+ return new AudioInputStream(byteStream, pcmFormat, AudioSystem.NOT_SPECIFIED);
+ }
+
+ static class ConversionThread extends Thread {
+ public final int num;
+ public byte[] resultArray = null;
+ public ConversionThread(int num) {
+ this.num = num;
+ }
+ @Override
+ public void run() {
+ log("ConversionThread[" + num + "] started.");
+ try {
+ InputStream inStream = new ByteArrayInputStream(pcmBuffer);
+
+ AudioInputStream pcmStream = new AudioInputStream(
+ inStream, pcmFormat, AudioSystem.NOT_SPECIFIED);
+ AudioInputStream alawStream = AudioSystem.getAudioInputStream(alawFormat, pcmStream);
+
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ int read = 0;
+ byte[] data = new byte[4096];
+ while((read = alawStream.read(data)) != -1) {
+ outStream.write(data, 0, read);
+ }
+ alawStream.close();
+ resultArray = outStream.toByteArray();
+ } catch (Exception ex) {
+ log("ConversionThread[" + num + "] exception:");
+ log(ex);
+ }
+ log("ConversionThread[" + num + "] completed.");
+ }
+ }
+
+ static void log(String s) {
+ System.out.println(s);
+ }
+
+ static void log(Exception ex) {
+ ex.printStackTrace(System.out);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileWriter/ExpectedNPEOnNull.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.spi.AudioFileWriter;
+
+import static java.util.ServiceLoader.load;
+import static javax.sound.sampled.AudioFileFormat.Type;
+import static javax.sound.sampled.AudioFormat.*;
+
+/**
+ * @test
+ * @bug 8135100
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ /**
+ * We will try to use all encoding, in this case all our providers will be
+ * covered by supported/unsupported encoding.
+ */
+ private static final Encoding[] encodings = {Encoding.PCM_SIGNED,
+ Encoding.PCM_UNSIGNED,
+ Encoding.PCM_FLOAT,
+ Encoding.ULAW, Encoding.ALAW,
+ new Encoding("test")};
+
+ /**
+ * We will try to use all types, in this case all our providers will be
+ * covered by supported/unsupported types.
+ */
+ private static final Type[] types = {Type.WAVE, Type.AU, Type.AIFF,
+ Type.AIFC, Type.SND,
+ new Type("MIDI", "mid"),
+ new Type("test", "test")};
+
+ /**
+ * We will try to use all supported AudioInputStream, in this case all our
+ * providers will be covered by supported/unsupported streams.
+ */
+ private static final List<AudioInputStream> aiss = new ArrayList<>();
+
+ static {
+ for (final Encoding encoding : encodings) {
+ for (final Type type : types) {
+ aiss.add(getAIS(type, encoding));
+ }
+ }
+ }
+
+ public static void main(final String[] args) throws Exception {
+ testAS();
+ for (final AudioFileWriter afw : load(AudioFileWriter.class)) {
+ testAFW(afw);
+ }
+ testAFW(customAFW);
+ }
+
+ /**
+ * Tests the part of AudioSystem API, which implemented via AudioFileWriter.
+ */
+ private static void testAS() throws Exception {
+
+ // AudioSystem#getAudioFileTypes(AudioInputStream)
+ try {
+ AudioSystem.getAudioFileTypes(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioSystem#isFileTypeSupported(Type)
+ try {
+ AudioSystem.isFileTypeSupported(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioSystem#isFileTypeSupported(Type, AudioInputStream)
+ for (final Type type : types) {
+ try {
+ AudioSystem.isFileTypeSupported(type, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.isFileTypeSupported(null, stream);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // AudioSystem#write(AudioInputStream, Type, OutputStream)
+ for (final Type type : types) {
+ try {
+ AudioSystem.write(null, type, new NullOutputStream());
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.write(stream, null, new NullOutputStream());
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Type type : types) {
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.write(stream, type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+
+ // AudioSystem#write(AudioInputStream, Type, File)
+ for (final Type type : types) {
+ try {
+ AudioSystem.write(null, type, new File("test.sound"));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.write(stream, null, new File("test.sound"));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ for (final Type type : types) {
+ try {
+ AudioSystem.write(stream, type, (File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Tests the AudioFileWriter API directly.
+ */
+ private static void testAFW(final AudioFileWriter afw) throws Exception {
+
+ // AudioFileWriter#isFileTypeSupported(Type)
+ try {
+ afw.isFileTypeSupported(null);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioFileWriter#getAudioFileTypes(AudioInputStream)
+ try {
+ afw.getAudioFileTypes(null);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioFileWriter#isFileTypeSupported(Type, AudioInputStream)
+ for (final Type type : types) {
+ try {
+ afw.isFileTypeSupported(type, null);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ afw.isFileTypeSupported(null, stream);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // AudioFileWriter#write(AudioInputStream, Type, OutputStream)
+ for (final Type type : types) {
+ try {
+ afw.write(null, type, new NullOutputStream());
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ afw.write(stream, null, new NullOutputStream());
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ for (final Type type : types) {
+ try {
+ afw.write(stream, type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+
+ // AudioFileWriter#write(AudioInputStream, Type, File)
+ for (final Type type : types) {
+ try {
+ afw.write(null, type, new File("test.sound"));
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ afw.write(stream, null, new File("test.sound"));
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ for (final Type type : types) {
+ try {
+ afw.write(stream, type, (File) null);
+ throw new RuntimeException("NPE is expected: " + afw);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Tests some default implementation of AudioFileWriter API, using the
+ * custom {@code AudioFileWriter}, which support nothing.
+ */
+ static final AudioFileWriter customAFW = new AudioFileWriter() {
+ @Override
+ public Type[] getAudioFileTypes() {
+ return new Type[0];
+ }
+
+ @Override
+ public Type[] getAudioFileTypes(final AudioInputStream stream) {
+ Objects.requireNonNull(stream);
+ return new Type[0];
+ }
+
+ @Override
+ public int write(AudioInputStream stream, Type fileType,
+ OutputStream out) {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
+ return 0;
+ }
+
+ @Override
+ public int write(AudioInputStream stream, Type fileType, File out) {
+ Objects.requireNonNull(stream);
+ Objects.requireNonNull(fileType);
+ Objects.requireNonNull(out);
+ return 0;
+ }
+ };
+
+ private static AudioInputStream getAIS(final Type type, Encoding encoding) {
+ AudioFormat af = new AudioFormat(encoding, 44100.0f, 16, 2, 1, 1, true);
+ AudioFileFormat aif = new AudioFileFormat(type, af, 0);
+ ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1024]);
+ return new AudioInputStream(bais, aif.getFormat(), 0);
+ }
+
+ private static final class NullOutputStream extends OutputStream {
+
+ @Override
+ public void write(final int b) {
+ //do nothing
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/AudioFileWriter/WriterCloseInput.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2011, 2013, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 7013521
+ * @summary AIFF/AU/WAVE writers close input audio stream
+ * @author Alex Menkov
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+
+
+public class WriterCloseInput {
+
+ final static AudioFormat audioFormat = new AudioFormat(44100f, 16, 2, true, true);
+ //final static AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 44100f, 8, 2, 2, 44100f, true);
+ final static int frameLength = 44100 * 2; // 2 seconds
+ final static byte[] dataBuffer
+ = new byte[frameLength * (audioFormat.getSampleSizeInBits()/8)
+ * audioFormat.getChannels()];
+
+ static int testTotal = 0;
+ static int testFailed = 0;
+
+ public static void main(String[] args) throws Exception {
+ test(AudioFileFormat.Type.AIFF);
+ test(AudioFileFormat.Type.AU);
+ test(AudioFileFormat.Type.WAVE);
+
+ if (testFailed == 0) {
+ out("All tests passed.");
+ } else {
+ out("" + testFailed + " of " + testTotal + " tests FAILED.");
+ System.out.flush();
+ throw new RuntimeException("Test FAILED.");
+ }
+ }
+
+ static void test(AudioFileFormat.Type fileType) {
+ test(fileType, frameLength);
+ test(fileType, AudioSystem.NOT_SPECIFIED);
+ }
+
+ static void test(AudioFileFormat.Type fileType, int length) {
+ test(fileType, length, false);
+ test(fileType, length, true);
+ }
+
+ static void test(AudioFileFormat.Type fileType, int length, boolean isFile) {
+ testTotal++;
+ out("Testing fileType: " + fileType
+ + ", frameLength: " + (length >= 0 ? length : "unspecified")
+ + ", output: " + (isFile ? "File" : "OutputStream"));
+ AudioInputStream inStream = new ThrowAfterCloseStream(
+ new ByteArrayInputStream(dataBuffer), audioFormat, length);
+
+ AudioSystem.isFileTypeSupported(fileType, inStream);
+
+ try {
+ if (isFile) {
+ File f = File.createTempFile("WriterCloseInput" + testTotal, "tmp");
+ AudioSystem.write(inStream, fileType, f);
+ f.delete();
+ } else {
+ OutputStream outStream = new NullOutputStream();
+ AudioSystem.write(inStream, fileType, outStream);
+ }
+ } catch (Exception ex) {
+ // this is not failure
+ out("SKIPPED (AudioSystem.write exception): " + ex.getMessage());
+ //out(ex);
+ inStream = null;
+ }
+
+ if (inStream != null) {
+ try {
+ // test if the stream is closed
+ inStream.available();
+ out("PASSED");
+ } catch (IOException ex) {
+ testFailed++;
+ out("FAILED: " + ex.getMessage());
+ //out(ex);
+ }
+ }
+ out("");
+ }
+
+ static class ThrowAfterCloseStream extends AudioInputStream {
+ private boolean closed = false;
+ public ThrowAfterCloseStream(InputStream in, AudioFormat format, long length) {
+ super(in, format, length);
+ }
+ @Override
+ public void close() {
+ closed = true;
+ }
+ @Override
+ public int available() throws IOException {
+ if (closed) {
+ throw new IOException("The stream has been closed");
+ }
+ return 1;
+ }
+ }
+
+ static class NullOutputStream extends OutputStream {
+ @Override
+ public void write(int b) throws IOException {
+ // nop
+ }
+ }
+
+ static void out(String s) {
+ System.out.println(s);
+ }
+
+ static void out(Exception ex) {
+ ex.printStackTrace(System.out);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/FormatConversionProvider/ExpectedNPEOnNull.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,356 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioFormat.Encoding;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.spi.FormatConversionProvider;
+
+import static java.util.ServiceLoader.load;
+import static javax.sound.sampled.AudioFileFormat.*;
+
+/**
+ * @test
+ * @bug 8135100
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ /**
+ * We will try to use all encoding, in this case all our providers will be
+ * covered by supported/unsupported encoding.
+ */
+ private static final Encoding[] encodings = {Encoding.PCM_SIGNED,
+ Encoding.PCM_UNSIGNED,
+ Encoding.PCM_FLOAT,
+ Encoding.ULAW, Encoding.ALAW,
+ new Encoding("test")};
+
+ /**
+ * We will try to use all types, in this case all our providers will be
+ * covered by supported/unsupported types.
+ */
+ private static final Type[] types = {Type.WAVE, Type.AU, Type.AIFF,
+ Type.AIFC, Type.SND,
+ new Type("MIDI", "mid"),
+ new Type("test", "test")};
+
+ /**
+ * We will try to use all supported AudioInputStream, in this case all our
+ * providers will be covered by supported/unsupported streams.
+ */
+ private static final List<AudioInputStream> aiss = new ArrayList<>();
+
+ static {
+ for (final Encoding encoding : encodings) {
+ for (final Type type : types) {
+ aiss.add(getAIS(type, encoding));
+ }
+ }
+ }
+
+ public static void main(final String[] args) throws Exception {
+ testAS();
+ for (final FormatConversionProvider fcp : load(
+ FormatConversionProvider.class)) {
+ testFCP(fcp);
+ }
+ testFCP(customFCP);
+ }
+
+ /**
+ * Tests the part of AudioSystem API, which implemented via
+ * FormatConversionProvider.
+ */
+ private static void testAS() throws Exception {
+
+ // AudioSystem#getAudioInputStream(Encoding, AudioInputStream)
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.getAudioInputStream(encoding, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.getAudioInputStream((Encoding) null, stream);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ // AudioSystem#getAudioInputStream(AudioFormat, AudioInputStream)
+ for (final AudioInputStream stream : aiss) {
+ try {
+ AudioSystem.getAudioInputStream((AudioFormat) null, stream);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.getAudioInputStream(getAFF(encoding), null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // AudioSystem#getTargetEncodings(AudioFormat)
+ try {
+ AudioSystem.getTargetEncodings((AudioFormat) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioSystem#getTargetEncodings(AudioFormat.Encoding)
+ try {
+ AudioSystem.getTargetEncodings((Encoding) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+
+ // AudioSystem#getTargetFormats(AudioFormat.Encoding, AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.getTargetFormats(null, getAFF(encoding));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.getTargetFormats(encoding, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.isConversionSupported((AudioFormat) null,
+ getAFF(encoding));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.isConversionSupported(getAFF(encoding), null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // AudioSystem#isConversionSupported(AudioFormat.Encoding, AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.isConversionSupported((Encoding) null,
+ getAFF(encoding));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ AudioSystem.isConversionSupported(encoding, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+
+ /**
+ * Tests the FormatConversionProvider API directly.
+ */
+ private static void testFCP(FormatConversionProvider fcp) throws Exception {
+
+ // FormatConversionProvider#isSourceEncodingSupported(Encoding)
+ try {
+ fcp.isSourceEncodingSupported(null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+
+ // FormatConversionProvider#isTargetEncodingSupported(Encoding)
+ try {
+ fcp.isTargetEncodingSupported(null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+
+ // FormatConversionProvider#getTargetEncodings()
+ try {
+ fcp.getTargetEncodings(null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+
+ // FormatConversionProvider#isConversionSupported(Encoding, AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.isConversionSupported((Encoding) null, getAFF(encoding));
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.isConversionSupported(encoding, null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // FormatConversionProvider#getTargetFormats(Encoding, AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.getTargetFormats(null, getAFF(encoding));
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.getTargetFormats(encoding, null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // FormatConversionProvider#isConversionSupported(AudioFormat,
+ // AudioFormat)
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.isConversionSupported((AudioFormat) null, getAFF(encoding));
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.isConversionSupported(getAFF(encoding), null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // FormatConversionProvider#getAudioInputStream(Encoding,
+ // AudioInputStream)
+ for (final AudioInputStream stream : aiss) {
+ try {
+ fcp.getAudioInputStream((Encoding) null, stream);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.getAudioInputStream(encoding, null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ // FormatConversionProvider#getAudioInputStream(AudioFormat,
+ // AudioInputStream)
+ for (final AudioInputStream stream : aiss) {
+ try {
+ fcp.getAudioInputStream((AudioFormat) null, stream);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final Encoding encoding : encodings) {
+ try {
+ fcp.getAudioInputStream(getAFF(encoding), null);
+ throw new RuntimeException("NPE is expected: " + fcp);
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+
+ /**
+ * Tests some default implementation of FormatConversionProvider API, using
+ * the custom {@code FormatConversionProvider}, which support nothing.
+ */
+ static FormatConversionProvider customFCP = new FormatConversionProvider() {
+
+ @Override
+ public Encoding[] getSourceEncodings() {
+ return new Encoding[0];
+ }
+
+ @Override
+ public Encoding[] getTargetEncodings() {
+ return new Encoding[0];
+ }
+
+ @Override
+ public Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
+ Objects.requireNonNull(sourceFormat);
+ return new Encoding[0];
+ }
+
+ @Override
+ public AudioFormat[] getTargetFormats(Encoding enc, AudioFormat frmt) {
+ Objects.requireNonNull(enc);
+ Objects.requireNonNull(frmt);
+ return new AudioFormat[0];
+ }
+
+ @Override
+ public AudioInputStream getAudioInputStream(Encoding encoding,
+ AudioInputStream stream) {
+ Objects.requireNonNull(encoding);
+ Objects.requireNonNull(stream);
+ return null;
+ }
+
+ @Override
+ public AudioInputStream getAudioInputStream(AudioFormat format,
+ AudioInputStream stream) {
+ Objects.requireNonNull(format);
+ Objects.requireNonNull(stream);
+ return null;
+ }
+ };
+
+ private static AudioFormat getAFF(final Encoding encoding) {
+ return new AudioFormat(encoding, 44100.0f, 16, 2, 1, 1, true);
+ }
+
+ private static AudioInputStream getAIS(final Type type, Encoding encoding) {
+ AudioFormat af = new AudioFormat(encoding, 44100.0f, 16, 2, 1, 1, true);
+ AudioFileFormat aif = new AudioFileFormat(type, af, 0);
+ ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1024]);
+ return new AudioInputStream(bais, aif.getFormat(), 0);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/sampled/spi/MixerProvider/ExpectedNPEOnNull.java Sun Nov 22 17:27:33 2015 +0300
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Mixer;
+import javax.sound.sampled.spi.MixerProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8135100
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testAS();
+ for (final MixerProvider mp : load(MixerProvider.class)) {
+ testMP(mp);
+ }
+ testMP(customMP);
+ }
+
+ /**
+ * Tests the part of AudioSystem API, which implemented via MixerProvider.
+ */
+ private static void testAS() {
+ try {
+ AudioSystem.getMixer(null); // null should be accepted
+ } catch (final SecurityException | IllegalArgumentException ignored) {
+ // skip the specified exceptions only
+ }
+ }
+
+ /**
+ * Tests the MixerProvider API directly.
+ */
+ private static void testMP(MixerProvider mp) {
+ try {
+ mp.isMixerSupported(null);
+ throw new RuntimeException("NPE is expected: " + mp);
+ } catch (final NullPointerException ignored) {
+
+ }
+ try {
+ mp.getMixer(null); // null should be accepted
+ } catch (SecurityException | IllegalArgumentException e) {
+ // skip the specified exceptions only
+ }
+ }
+
+ /**
+ * Tests some default implementation of MixerProvider API, using the
+ * custom {@code MixerProvider}, which support nothing.
+ */
+ static final MixerProvider customMP = new MixerProvider() {
+ @Override
+ public Mixer.Info[] getMixerInfo() {
+ return new Mixer.Info[0];
+ }
+
+ @Override
+ public Mixer getMixer(Mixer.Info info) {
+ return null;
+ }
+ };
+}