--- old/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java 2015-09-14 15:32:01.000000000 +0300 +++ new/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java 2015-09-14 15:32:01.000000000 +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; @@ -696,8 +697,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 codecs = getFormatConversionProviders(); Vector encodings = new Vector<>(); @@ -730,9 +733,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 codecs = getFormatConversionProviders(); Vector encodings = new Vector<>(); @@ -769,9 +773,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 codecs = getFormatConversionProviders(); @@ -792,6 +799,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 +808,8 @@ */ public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { + Objects.requireNonNull(targetEncoding); + Objects.requireNonNull(sourceStream); List codecs = getFormatConversionProviders(); @@ -821,8 +832,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 codecs = getFormatConversionProviders(); Vector formats = new Vector<>(); @@ -860,8 +875,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 codecs = getFormatConversionProviders(); @@ -882,6 +901,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 +910,6 @@ */ public static AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) { - if (sourceStream.getFormat().matches(targetFormat)) { return sourceStream; } @@ -924,11 +944,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 providers = getAudioFileReaders(); AudioFileFormat format = null; @@ -961,9 +983,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 providers = getAudioFileReaders(); AudioFileFormat format = null; @@ -996,9 +1020,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 providers = getAudioFileReaders(); AudioFileFormat format = null; @@ -1037,11 +1063,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 providers = getAudioFileReaders(); AudioInputStream audioStream = null; @@ -1074,9 +1102,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 providers = getAudioFileReaders(); AudioInputStream audioStream = null; @@ -1109,9 +1139,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 providers = getAudioFileReaders(); AudioInputStream audioStream = null; @@ -1163,9 +1195,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 providers = getAudioFileWriters(); for(int i=0; i < providers.size(); i++) { @@ -1185,8 +1218,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 providers = getAudioFileWriters(); Set returnTypesSet = new HashSet<>(); @@ -1210,10 +1245,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 providers = getAudioFileWriters(); for(int i=0; i < providers.size(); i++) { @@ -1241,11 +1279,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 providers = getAudioFileWriters(); int bytesWritten = 0; @@ -1281,11 +1324,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 providers = getAudioFileWriters(); int bytesWritten = 0;