Java Code Examples for javax.sound.sampled.spi.FormatConversionProvider

The following examples show how to use javax.sound.sampled.spi.FormatConversionProvider. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Java8CN   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 2
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 3
Source Project: jdk8u-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 4
Source Project: jdk8u_jdk   Source File: JDK13Services.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 5
Source Project: jdk8u-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 6
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 7
Source Project: TencentKona-8   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 8
Source Project: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 9
Source Project: jdk8u_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 10
Source Project: openjdk-8-source   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 11
Source Project: jdk8u-jdk   Source File: JDK13Services.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 12
Source Project: hottub   Source File: JDK13Services.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 13
Source Project: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 14
Source Project: JDKSourceCode1.8   Source File: AudioSystem.java    License: MIT License 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 15
Source Project: openjdk-jdk8u   Source File: JDK13Services.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 16
Source Project: jdk8u-jdk   Source File: JDK13Services.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 17
Source Project: openjdk-jdk8u   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 18
/**
 * Obtains a List containing installed instances of the providers for the
 * requested service. The returned List is immutable.
 *
 * @param serviceClass The type of providers requested. This should be one
 *                     of AudioFileReader.class, AudioFileWriter.class,
 *                     FormatConversionProvider.class, MixerProvider.class,
 *                     MidiDeviceProvider.class, MidiFileReader.class,
 *                     MidiFileWriter.class or SoundbankReader.class.
 *
 * @return A List of providers of the requested type. This List is
 *         immutable.
 */
public static List<?> getProviders(final Class<?> serviceClass) {
    final List<?> providers;
    if (!MixerProvider.class.equals(serviceClass)
            && !FormatConversionProvider.class.equals(serviceClass)
            && !AudioFileReader.class.equals(serviceClass)
            && !AudioFileWriter.class.equals(serviceClass)
            && !MidiDeviceProvider.class.equals(serviceClass)
            && !SoundbankReader.class.equals(serviceClass)
            && !MidiFileWriter.class.equals(serviceClass)
            && !MidiFileReader.class.equals(serviceClass)) {
        providers = new ArrayList<>(0);
    } else {
        providers = JSSecurityManager.getProviders(serviceClass);
    }
    return Collections.unmodifiableList(providers);
}
 
Example 19
Source Project: jdk8u-dev-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 20
Source Project: Bytecoder   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an audio input
 * stream with the specified format using the set of installed format
 * converters.
 *
 * @param  sourceFormat the audio format for which conversion is queried
 * @return array of encodings. If {@code sourceFormat}is not supported, an
 *         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();
    List<AudioFormat.Encoding> encs = new ArrayList<>();

    // gather from all the codecs
    for (final FormatConversionProvider codec : codecs) {
        Collections.addAll(encs, codec.getTargetEncodings(sourceFormat));
    }

    if (!encs.contains(sourceFormat.getEncoding())) {
        encs.add(sourceFormat.getEncoding());
    }

    return encs.toArray(new AudioFormat.Encoding[encs.size()]);
}
 
Example 21
Source Project: Bytecoder   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Indicates whether an audio input stream of the specified encoding can be
 * obtained from an audio input stream that has the specified format.
 *
 * @param  targetEncoding the desired encoding after conversion
 * @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);
    if (sourceFormat.getEncoding().equals(targetEncoding)) {
        return true;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = codecs.get(i);
        if(codec.isConversionSupported(targetEncoding,sourceFormat) ) {
            return true;
        }
    }
    return false;
}
 
Example 22
Source Project: Bytecoder   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated encoding, by converting
 * the provided audio input stream.
 *
 * @param  targetEncoding the desired encoding after conversion
 * @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)
 * @see #getAudioInputStream(AudioFormat, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
                                                   AudioInputStream sourceStream) {
    Objects.requireNonNull(targetEncoding);
    Objects.requireNonNull(sourceStream);
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding)) {
        return sourceStream;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = codecs.get(i);
        if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) {
            return codec.getAudioInputStream( targetEncoding, sourceStream );
        }
    }
    // we ran out of options, throw an exception
    throw new IllegalArgumentException("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat());
}
 
Example 23
Source Project: Bytecoder   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 *
 * @param  targetFormat the desired audio format after conversion
 * @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)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {
    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 24
Source Project: jdk8u_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated format, by converting the
 * provided audio input stream.
 * @param targetFormat the desired audio format after conversion
 * @param sourceStream the stream to be converted
 * @return an audio input stream of the indicated format
 * @throws IllegalArgumentException if the conversion is not supported
 * #see #getTargetEncodings(AudioFormat)
 * @see #getTargetFormats(AudioFormat.Encoding, AudioFormat)
 * @see #isConversionSupported(AudioFormat, AudioFormat)
 * @see #getAudioInputStream(AudioFormat.Encoding, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat targetFormat,
                                                   AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
        return sourceStream;
    }

    List codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if(codec.isConversionSupported(targetFormat,sourceStream.getFormat()) ) {
            return codec.getAudioInputStream(targetFormat,sourceStream);
        }
    }

    // we ran out of options...
    throw new IllegalArgumentException("Unsupported conversion: " + targetFormat + " from " + sourceStream.getFormat());
}
 
Example 25
Source Project: jdk8u-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified encoding using the set
 * of installed format converters.
 * @param sourceEncoding the encoding for which conversion support
 * is queried
 * @return array of encodings.  If <code>sourceEncoding</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing <code>sourceEncoding</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    AudioFormat.Encoding encs2[] = (AudioFormat.Encoding[]) encodings.toArray(new AudioFormat.Encoding[0]);
    return encs2;
}
 
Example 26
Source Project: openjdk-jdk9   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an audio input
 * stream with the specified encoding using the set of installed format
 * converters.
 *
 * @param  sourceEncoding the encoding for which conversion support is
 *         queried
 * @return array of encodings. If {@code sourceEncoding}is not supported, an
 *         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<>();

    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs
    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = codecs.get(i);
        if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
            encs = codec.getTargetEncodings();
            for (int j = 0; j < encs.length; j++) {
                encodings.addElement( encs[j] );
            }
        }
    }
    if (!encodings.contains(sourceEncoding)) {
        encodings.addElement(sourceEncoding);
    }

    return encodings.toArray(new AudioFormat.Encoding[encodings.size()]);
}
 
Example 27
Source Project: openjdk-jdk9   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an audio input
 * stream with the specified format using the set of installed format
 * converters.
 *
 * @param  sourceFormat the audio format for which conversion is queried
 * @return array of encodings. If {@code sourceFormat}is not supported, an
 *         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();
    List<AudioFormat.Encoding> encs = new ArrayList<>();

    // gather from all the codecs
    for (final FormatConversionProvider codec : codecs) {
        Collections.addAll(encs, codec.getTargetEncodings(sourceFormat));
    }

    if (!encs.contains(sourceFormat.getEncoding())) {
        encs.add(sourceFormat.getEncoding());
    }

    return encs.toArray(new AudioFormat.Encoding[encs.size()]);
}
 
Example 28
Source Project: openjdk-jdk9   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an audio input stream of the indicated encoding, by converting
 * the provided audio input stream.
 *
 * @param  targetEncoding the desired encoding after conversion
 * @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)
 * @see #getAudioInputStream(AudioFormat, AudioInputStream)
 */
public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
                                                   AudioInputStream sourceStream) {
    Objects.requireNonNull(targetEncoding);
    Objects.requireNonNull(sourceStream);
    if (sourceStream.getFormat().getEncoding().equals(targetEncoding)) {
        return sourceStream;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i = 0; i < codecs.size(); i++) {
        FormatConversionProvider codec = codecs.get(i);
        if( codec.isConversionSupported( targetEncoding, sourceStream.getFormat() ) ) {
            return codec.getAudioInputStream( targetEncoding, sourceStream );
        }
    }
    // we ran out of options, throw an exception
    throw new IllegalArgumentException("Unsupported conversion: " + targetEncoding + " from " + sourceStream.getFormat());
}
 
Example 29
Source Project: jdk8u-dev-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtains the formats that have a particular encoding and that the system can
 * obtain from a stream of the specified format using the set of
 * installed format converters.
 * @param targetEncoding the desired encoding after conversion
 * @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.
 */
public static AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) {

    List codecs = getFormatConversionProviders();
    Vector formats = new Vector();

    int size = 0;
    int index = 0;
    AudioFormat fmts[] = null;

    // gather from all the codecs

    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = (FormatConversionProvider) codecs.get(i);
        fmts = codec.getTargetFormats(targetEncoding, sourceFormat);
        size += fmts.length;
        formats.addElement( fmts );
    }

    // now build a new array

    AudioFormat fmts2[] = new AudioFormat[size];
    for(int i=0; i<formats.size(); i++ ) {
        fmts = (AudioFormat [])(formats.get(i));
        for(int j=0; j<fmts.length; j++ ) {
            fmts2[index++] = fmts[j];
        }
    }
    return fmts2;
}
 
Example 30
Source Project: jdk1.8-source-analysis   Source File: AudioSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the encodings that the system can obtain from an
 * audio input stream with the specified format using the set
 * of installed format converters.
 * @param sourceFormat the audio format for which conversion
 * is queried
 * @return array of encodings. If <code>sourceFormat</code>is not supported,
 * an array of length 0 is returned. Otherwise, the array will have a length
 * of at least 1, representing the encoding of <code>sourceFormat</code> (no conversion).
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {


    List codecs = getFormatConversionProviders();
    Vector encodings = new Vector();

    int size = 0;
    int index = 0;
    AudioFormat.Encoding encs[] = null;

    // gather from all the codecs

    for(int i=0; i<codecs.size(); i++ ) {
        encs = ((FormatConversionProvider) codecs.get(i)).getTargetEncodings(sourceFormat);
        size += encs.length;
        encodings.addElement( encs );
    }

    // now build a new array

    AudioFormat.Encoding encs2[] = new AudioFormat.Encoding[size];
    for(int i=0; i<encodings.size(); i++ ) {
        encs = (AudioFormat.Encoding [])(encodings.get(i));
        for(int j=0; j<encs.length; j++ ) {
            encs2[index++] = encs[j];
        }
    }
    return encs2;
}