8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
The specification change was reviewed by Florian Bomers also Reviewed-by: amenkov
This commit is contained in:
parent
90c71390a7
commit
08c1fe55c0
@ -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.ByteArrayInputStream;
|
||||
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 final class AiffFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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 final class AiffFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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);
|
||||
|
@ -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 final class AlawCodec extends SunCodec {
|
||||
/**
|
||||
*/
|
||||
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 );
|
||||
|
@ -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.ByteArrayInputStream;
|
||||
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 final class AuFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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 final class AuFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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);
|
||||
|
@ -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.IOException;
|
||||
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 final class AudioFloatFormatConverter extends FormatConversionProvider {
|
||||
|
||||
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 final class AudioFloatFormatConverter extends FormatConversionProvider {
|
||||
|
||||
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 final class AudioFloatFormatConverter extends FormatConversionProvider {
|
||||
|
||||
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++) {
|
||||
|
@ -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 @@ public final class DirectAudioDeviceProvider extends MixerProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Mixer %s not supported by this provider", info));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 final class PCMtoPCMCodec extends SunCodec {
|
||||
/**
|
||||
*/
|
||||
public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
|
||||
// filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
|
||||
|
||||
|
@ -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 final class PortMixerProvider extends MixerProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Mixer getMixer(Mixer.Info info) {
|
||||
synchronized (PortMixerProvider.class) {
|
||||
for (int i = 0; i < infos.length; i++) {
|
||||
@ -110,8 +109,8 @@ public final class PortMixerProvider extends MixerProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Mixer " + info.toString()
|
||||
+ " not supported by this provider.");
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Mixer %s not supported by this provider", info));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 @@ package com.sun.media.sound;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
@ -106,6 +107,8 @@ public final class UlawCodec extends SunCodec {
|
||||
/**
|
||||
*/
|
||||
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()))
|
||||
||
|
||||
|
@ -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.ByteArrayInputStream;
|
||||
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 final class WaveFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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 final class WaveFileWriter extends SunFileWriter {
|
||||
|
||||
|
||||
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);
|
||||
|
@ -33,6 +33,7 @@ import java.net.URL;
|
||||
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 @@ public class AudioSystem {
|
||||
* 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 @@ public class AudioSystem {
|
||||
* 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 @@ public class AudioSystem {
|
||||
* 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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 class AudioSystem {
|
||||
*/
|
||||
public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
|
||||
AudioInputStream sourceStream) {
|
||||
Objects.requireNonNull(targetEncoding);
|
||||
Objects.requireNonNull(sourceStream);
|
||||
|
||||
List<FormatConversionProvider> codecs = getFormatConversionProviders();
|
||||
|
||||
@ -821,8 +803,12 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 class AudioSystem {
|
||||
*/
|
||||
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
|
||||
AudioInputStream sourceStream) {
|
||||
|
||||
if (sourceStream.getFormat().matches(targetFormat)) {
|
||||
return sourceStream;
|
||||
}
|
||||
@ -924,11 +915,13 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* 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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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 @@ public class AudioSystem {
|
||||
* @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;
|
||||
|
@ -60,6 +60,7 @@ public abstract class AudioFileReader {
|
||||
* @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 @@ public abstract class AudioFileReader {
|
||||
* @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 @@ public abstract class AudioFileReader {
|
||||
* @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 @@ public abstract class AudioFileReader {
|
||||
* @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 @@ public abstract class AudioFileReader {
|
||||
* @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 @@ public abstract class AudioFileReader {
|
||||
* @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;
|
||||
|
@ -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 @@ package javax.sound.sampled.spi;
|
||||
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 @@ public abstract class AudioFileWriter {
|
||||
* @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 @@ public abstract class AudioFileWriter {
|
||||
* 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 @@ public abstract class AudioFileWriter {
|
||||
* @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 @@ public abstract class AudioFileWriter {
|
||||
* @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 @@ public abstract class AudioFileWriter {
|
||||
* @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
|
||||
*/
|
||||
|
@ -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 @@ public abstract class FormatConversionProvider {
|
||||
* 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 @@ public abstract class FormatConversionProvider {
|
||||
* 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 @@ public abstract class FormatConversionProvider {
|
||||
*
|
||||
* @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 @@ public abstract class FormatConversionProvider {
|
||||
* @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 @@ public abstract class FormatConversionProvider {
|
||||
|
||||
/**
|
||||
* 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 @@ public abstract class FormatConversionProvider {
|
||||
* @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 @@ public abstract class FormatConversionProvider {
|
||||
* 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 @@ public abstract class FormatConversionProvider {
|
||||
* 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);
|
||||
|
@ -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 @@ public abstract class MixerProvider {
|
||||
* 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 class MixerProvider {
|
||||
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)
|
||||
*/
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user