java类javax.sound.sampled.spi.FormatConversionProvider的实例源码

JDK13Services.java 文件源码 项目:OpenJSharp 阅读 17 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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());
}
JDK13Services.java 文件源码 项目:jdk8u-jdk 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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());
}
JDK13Services.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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());
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Indicates whether an audio input stream of a specified format can be
 * obtained from an audio input stream of another specified format.
 *
 * @param  targetFormat the desired audio format after conversion
 * @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);
    if (sourceFormat.matches(targetFormat)) {
        return true;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = codecs.get(i);
        if(codec.isConversionSupported(targetFormat, sourceFormat) ) {
            return true;
        }
    }
    return false;
}
AudioSystem.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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());
}
JDK13Services.java 文件源码 项目:openjdk9 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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()]);
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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());
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Indicates whether an audio input stream of a specified format can be
 * obtained from an audio input stream of another specified format.
 *
 * @param  targetFormat the desired audio format after conversion
 * @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);
    if (sourceFormat.matches(targetFormat)) {
        return true;
    }

    List<FormatConversionProvider> codecs = getFormatConversionProviders();

    for(int i=0; i<codecs.size(); i++ ) {
        FormatConversionProvider codec = codecs.get(i);
        if(codec.isConversionSupported(targetFormat, sourceFormat) ) {
            return true;
        }
    }
    return false;
}
AudioSystem.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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());
}
AudioSystem.java 文件源码 项目:Java8CN 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:Java8CN 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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());
}
JDK13Services.java 文件源码 项目:jdk8u_jdk 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:jdk8u_jdk 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:jdk8u_jdk 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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());
}
JDK13Services.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AudioSystem.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AudioSystem.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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());
}
AudioSystem.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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());
}
AudioSystem.java 文件源码 项目:javify 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Given a source encoding, return an array of all target encodings to which
 * data in this form can be converted.
 * @param source the source encoding
 */
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding source)
{
  HashSet<AudioFormat.Encoding> result
    = new HashSet<AudioFormat.Encoding>();
  Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
  while (i.hasNext())
    {
      FormatConversionProvider prov = (FormatConversionProvider) i.next();
      if (! prov.isSourceEncodingSupported(source))
        continue;
      AudioFormat.Encoding[] es = prov.getTargetEncodings();
      for (int j = 0; j < es.length; ++j)
        result.add(es[j]);
    }
  return result.toArray(new AudioFormat.Encoding[result.size()]);
}


问题


面经


文章

微信
公众号

扫码关注公众号