1 /*
   2  * Copyright (c) 1999, 2002, 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.net.URL;
  32 
  33 import javax.sound.sampled.AudioFileFormat;
  34 import javax.sound.sampled.AudioInputStream;
  35 import javax.sound.sampled.UnsupportedAudioFileException;
  36 
  37 /**
  38  * Provider for audio file reading services.  Classes providing concrete
  39  * implementations can parse the format information from one or more types of
  40  * audio file, and can produce audio input streams from files of these types.
  41  *
  42  * @author Kara Kytle
  43  * @since 1.3
  44  */
  45 public abstract class AudioFileReader {
  46 
  47     /**
  48      * Obtains the audio file format of the input stream provided.  The stream must
  49      * point to valid audio file data.  In general, audio file readers may
  50      * need to read some data from the stream before determining whether they
  51      * support it.  These parsers must
  52      * be able to mark the stream, read enough data to determine whether they
  53      * support the stream, and, if not, reset the stream's read pointer to its original
  54      * position.  If the input stream does not support this, this method may fail
  55      * with an <code>IOException</code>.
  56      * @param stream the input stream from which file format information should be
  57      * extracted
  58      * @return an <code>AudioFileFormat</code> object describing the audio file format
  59      * @throws UnsupportedAudioFileException if the stream does not point to valid audio
  60      * file data recognized by the system
  61      * @throws IOException if an I/O exception occurs
  62      * @see InputStream#markSupported
  63      * @see InputStream#mark
  64      */
  65     public abstract AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException;
  66 
  67     /**
  68      * Obtains the audio file format of the URL provided.  The URL must
  69      * point to valid audio file data.
  70      * @param url the URL from which file format information should be
  71      * extracted
  72      * @return an <code>AudioFileFormat</code> object describing the audio file format
  73      * @throws UnsupportedAudioFileException if the URL does not point to valid audio
  74      * file data recognized by the system
  75      * @throws IOException if an I/O exception occurs
  76      */
  77     public abstract AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException;
  78 
  79     /**
  80      * Obtains the audio file format of the <code>File</code> provided.  The <code>File</code> must
  81      * point to valid audio file data.
  82      * @param file the <code>File</code> from which file format information should be
  83      * extracted
  84      * @return an <code>AudioFileFormat</code> object describing the audio file format
  85      * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
  86      * file data recognized by the system
  87      * @throws IOException if an I/O exception occurs
  88      */
  89     public abstract AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException;
  90 
  91     /**
  92      * Obtains an audio input stream from the input stream provided.  The stream must
  93      * point to valid audio file data.  In general, audio file readers may
  94      * need to read some data from the stream before determining whether they
  95      * support it.  These parsers must
  96      * be able to mark the stream, read enough data to determine whether they
  97      * support the stream, and, if not, reset the stream's read pointer to its original
  98      * position.  If the input stream does not support this, this method may fail
  99      * with an <code>IOException</code>.
 100      * @param stream the input stream from which the <code>AudioInputStream</code> should be
 101      * constructed
 102      * @return an <code>AudioInputStream</code> object based on the audio file data contained
 103      * in the input stream.
 104      * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 105      * file data recognized by the system
 106      * @throws IOException if an I/O exception occurs
 107      * @see InputStream#markSupported
 108      * @see InputStream#mark
 109      */
 110     public abstract AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException;
 111 
 112     /**
 113      * Obtains an audio input stream from the URL provided.  The URL must
 114      * point to valid audio file data.
 115      * @param url the URL for which the <code>AudioInputStream</code> should be
 116      * constructed
 117      * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 118      * to by the URL
 119      * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 120      * file data recognized by the system
 121      * @throws IOException if an I/O exception occurs
 122      */
 123     public abstract AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException;
 124 
 125     /**
 126      * Obtains an audio input stream from the <code>File</code> provided.  The <code>File</code> must
 127      * point to valid audio file data.
 128      * @param file the <code>File</code> for which the <code>AudioInputStream</code> should be
 129      * constructed
 130      * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 131      * to by the File
 132      * @throws UnsupportedAudioFileException if the <code>File</code> does not point to valid audio
 133      * file data recognized by the system
 134      * @throws IOException if an I/O exception occurs
 135      */
 136     public abstract AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException;
 137 }