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

The following examples show how to use javax.sound.sampled.spi.AudioFileWriter. 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: jdk1.8-source-analysis   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 2
Source Project: jdk1.8-source-analysis   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 3
Source Project: jdk8u-jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 4
Source Project: jdk1.8-source-analysis   Source File: AudioSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 5
/**
 * 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 6
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 7
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 8
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 9
Source Project: dragonwell8_jdk   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 10
Source Project: TencentKona-8   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 11
Source Project: TencentKona-8   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 12
Source Project: TencentKona-8   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 13
Source Project: TencentKona-8   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 14
Source Project: TencentKona-8   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 15
Source Project: jdk8u60   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: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 17
Source Project: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 18
Source Project: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 19
Source Project: jdk8u60   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 20
Source Project: JDKSourceCode1.8   Source File: AudioSystem.java    License: MIT License 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: AudioSystem.java    License: MIT License 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 22
Source Project: JDKSourceCode1.8   Source File: AudioSystem.java    License: MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 23
Source Project: JDKSourceCode1.8   Source File: AudioSystem.java    License: MIT License 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 24
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 25
Source Project: openjdk-jdk8u   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 26
Source Project: openjdk-jdk8u   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains the file types that the system can write from the
 * audio input stream specified.
 * @param stream the audio input stream for which audio file type support
 * is queried
 * @return array of file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream) {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes(stream);
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}
 
Example 27
Source Project: openjdk-jdk8u   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 28
Source Project: openjdk-jdk8u   Source File: AudioSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the external file provided.
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the external file to which the file data should be written
 * @return the number of bytes written to the file
 * @throws IOException if an I/O exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        File out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if (!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
Example 29
/**
 * 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 30
/**
 * Obtains the file types for which file writing support is provided by the system.
 * @return array of unique file types.  If no file types are supported,
 * an array of length 0 is returned.
 */
public static AudioFileFormat.Type[] getAudioFileTypes() {
    List providers = getAudioFileWriters();
    Set returnTypesSet = new HashSet();

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        AudioFileFormat.Type[] fileTypes = writer.getAudioFileTypes();
        for(int j=0; j < fileTypes.length; j++) {
            returnTypesSet.add(fileTypes[j]);
        }
    }
    AudioFileFormat.Type returnTypes[] = (AudioFileFormat.Type[])
        returnTypesSet.toArray(new AudioFileFormat.Type[0]);
    return returnTypes;
}