src/share/classes/javax/sound/sampled/spi/AudioFileWriter.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.sound.sampled.spi;
  27 
  28 import java.io.File;
  29 import java.io.InputStream;
  30 import java.io.IOException;
  31 import java.io.OutputStream;
  32 
  33 import javax.sound.sampled.AudioFileFormat;
  34 import javax.sound.sampled.AudioInputStream;
  35 

  36 
  37 /**
  38  * Provider for audio file writing services.  Classes providing concrete
  39  * implementations can write one or more types of audio file from an audio
  40  * stream.
  41  *
  42  * @author Kara Kytle
  43  * @since 1.3
  44  */
  45 public abstract class AudioFileWriter {
  46 
  47     /**
  48      * Obtains the file types for which file writing support is provided by this
  49      * audio file writer.
  50      * @return array of file types.  If no file types are supported,
  51      * an array of length 0 is returned.

  52      */
  53     public abstract AudioFileFormat.Type[] getAudioFileTypes();
  54 
  55 
  56     /**
  57      * Indicates whether file writing support for the specified file type is provided
  58      * by this audio file writer.

  59      * @param fileType the file type for which write capabilities are queried
  60      * @return <code>true</code> if the file type is supported,
  61      * otherwise <code>false</code>
  62      */
  63     public boolean isFileTypeSupported(AudioFileFormat.Type fileType) {
  64 
  65         AudioFileFormat.Type types[] = getAudioFileTypes();
  66 
  67         for(int i=0; i<types.length; i++) {
  68             if( fileType.equals( types[i] ) ) {
  69                 return true;
  70             }
  71         }
  72         return false;
  73     }
  74 
  75 
  76     /**
  77      * Obtains the file types that this audio file writer can write from the
  78      * audio input stream specified.

  79      * @param stream the audio input stream for which audio file type support
  80      * is queried
  81      * @return array of file types.  If no file types are supported,
  82      * an array of length 0 is returned.
  83      */
  84     public abstract AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream);
  85 
  86 
  87     /**
  88      * Indicates whether an audio file of the type specified can be written
  89      * from the audio input stream indicated.

  90      * @param fileType file type for which write capabilities are queried
  91      * @param stream for which file writing support is queried
  92      * @return <code>true</code> if the file type is supported for this audio input stream,
  93      * otherwise <code>false</code>
  94      */
  95     public boolean isFileTypeSupported(AudioFileFormat.Type fileType, AudioInputStream stream) {
  96 
  97         AudioFileFormat.Type types[] = getAudioFileTypes( stream );
  98 
  99         for(int i=0; i<types.length; i++) {
 100             if( fileType.equals( types[i] ) ) {
 101                 return true;
 102             }
 103         }
 104         return false;
 105     }
 106 
 107 
 108     /**
 109      * Writes a stream of bytes representing an audio file of the file type
 110      * indicated to the output stream provided.  Some file types require that
 111      * the length be written into the file header, and cannot be written from
 112      * start to finish unless the length is known in advance.  An attempt
 113      * to write such a file type will fail with an IOException if the length in
 114      * the audio file format is
 115      * {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED AudioSystem.NOT_SPECIFIED}.
 116      * @param stream the audio input stream containing audio data to be
 117      * written to the output stream

 118      * @param fileType file type to be written to the output stream
 119      * @param out stream to which the file data should be written
 120      * @return the number of bytes written to the output stream
 121      * @throws IOException if an I/O exception occurs
 122      * @throws IllegalArgumentException if the file type is not supported by
 123      * the system
 124      * @see #isFileTypeSupported(AudioFileFormat.Type, AudioInputStream)
 125      * @see #getAudioFileTypes
 126      */
 127     public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException;
 128 
 129 
 130     /**
 131      * Writes a stream of bytes representing an audio file of the file format
 132      * indicated to the external file provided.
 133      * @param stream the audio input stream containing audio data to be
 134      * written to the file

 135      * @param fileType file type to be written to the file
 136      * @param out external file to which the file data should be written
 137      * @return the number of bytes written to the file
 138      * @throws IOException if an I/O exception occurs
 139      * @throws IllegalArgumentException if the file format is not supported by
 140      * the system
 141      * @see #isFileTypeSupported
 142      * @see #getAudioFileTypes
 143      */
 144     public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException;
 145 
 146 
 147 }
   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.sound.sampled.spi;
  27 
  28 import java.io.File;

  29 import java.io.IOException;
  30 import java.io.OutputStream;
  31 

  32 import javax.sound.sampled.AudioInputStream;
  33 
  34 import static javax.sound.sampled.AudioFileFormat.Type;
  35 
  36 /**
  37  * Provider for audio file writing services. Classes providing concrete
  38  * implementations can write one or more types of audio file from an audio
  39  * stream.
  40  *
  41  * @author Kara Kytle
  42  * @since 1.3
  43  */
  44 public abstract class AudioFileWriter {
  45 
  46     /**
  47      * Obtains the file types for which file writing support is provided by this
  48      * audio file writer.
  49      *
  50      * @return array of file types. If no file types are supported, an array of
  51      *         length 0 is returned.
  52      */
  53     public abstract Type[] getAudioFileTypes();

  54 
  55     /**
  56      * Indicates whether file writing support for the specified file type is
  57      * provided by this audio file writer.
  58      *
  59      * @param  fileType the file type for which write capabilities are queried
  60      * @return {@code true} if the file type is supported, otherwise
  61      *         {@code false}
  62      */
  63     public boolean isFileTypeSupported(Type fileType) {
  64 
  65         Type types[] = getAudioFileTypes();
  66 
  67         for(int i=0; i<types.length; i++) {
  68             if( fileType.equals( types[i] ) ) {
  69                 return true;
  70             }
  71         }
  72         return false;
  73     }
  74 

  75     /**
  76      * Obtains the file types that this audio file writer can write from the
  77      * audio input stream specified.
  78      *
  79      * @param  stream the audio input stream for which audio file type support
  80      *         is queried
  81      * @return array of file types. If no file types are supported, an array of
  82      *         length 0 is returned.
  83      */
  84     public abstract Type[] getAudioFileTypes(AudioInputStream stream);

  85 
  86     /**
  87      * Indicates whether an audio file of the type specified can be written from
  88      * the audio input stream indicated.
  89      *
  90      * @param  fileType file type for which write capabilities are queried
  91      * @param  stream for which file writing support is queried
  92      * @return {@code true} if the file type is supported for this audio input
  93      *         stream, otherwise {@code false}
  94      */
  95     public boolean isFileTypeSupported(Type fileType, AudioInputStream stream) {
  96 
  97         Type types[] = getAudioFileTypes( stream );
  98 
  99         for(int i=0; i<types.length; i++) {
 100             if( fileType.equals( types[i] ) ) {
 101                 return true;
 102             }
 103         }
 104         return false;
 105     }
 106 

 107     /**
 108      * Writes a stream of bytes representing an audio file of the file type
 109      * indicated to the output stream provided. Some file types require that
 110      * the length be written into the file header, and cannot be written from
 111      * start to finish unless the length is known in advance. An attempt to
 112      * write such a file type will fail with an IOException if the length in the
 113      * audio file format is {@link javax.sound.sampled.AudioSystem#NOT_SPECIFIED
 114      * AudioSystem.NOT_SPECIFIED}.
 115      *
 116      * @param  stream the audio input stream containing audio data to be written
 117      *         to the output stream
 118      * @param  fileType file type to be written to the output stream
 119      * @param  out stream to which the file data should be written
 120      * @return the number of bytes written to the output stream
 121      * @throws IOException if an I/O exception occurs
 122      * @throws IllegalArgumentException if the file type is not supported by the
 123      *         system
 124      * @see #isFileTypeSupported(Type, AudioInputStream)
 125      * @see #getAudioFileTypes
 126      */
 127     public abstract int write(AudioInputStream stream, Type fileType,
 128                               OutputStream out) throws IOException;
 129 
 130     /**
 131      * Writes a stream of bytes representing an audio file of the file format
 132      * indicated to the external file provided.
 133      *
 134      * @param  stream the audio input stream containing audio data to be written
 135      *         to the file
 136      * @param  fileType file type to be written to the file
 137      * @param  out external file to which the file data should be written
 138      * @return the number of bytes written to the file
 139      * @throws IOException if an I/O exception occurs
 140      * @throws IllegalArgumentException if the file format is not supported by
 141      *         the system
 142      * @see #isFileTypeSupported
 143      * @see #getAudioFileTypes
 144      */
 145     public abstract int write(AudioInputStream stream, Type fileType, File out)
 146             throws IOException;

 147 }