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.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
  49      * must 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 be able to mark the stream, read enough
  52      * data to determine whether they support the stream, and, if not, reset the
  53      * stream's read pointer to its original position. If the input stream does
  54      * not support this, this method may fail with an {@code IOException}.
  55      *
  56      * @param  stream the input stream from which file format information should
  57      *         be extracted
  58      * @return an {@code AudioFileFormat} object describing the audio file
  59      *         format
  60      * @throws UnsupportedAudioFileException if the stream does not point to
  61      *         valid audio file data recognized by the system
  62      * @throws IOException if an I/O exception occurs
  63      * @see InputStream#markSupported
  64      * @see InputStream#mark
  65      */
  66     public abstract AudioFileFormat getAudioFileFormat(InputStream stream)
  67             throws UnsupportedAudioFileException, IOException;
  68 
  69     /**
  70      * Obtains the audio file format of the URL provided. The URL must point to
  71      * valid audio file data.
  72      *
  73      * @param  url the URL from which file format information should be
  74      *         extracted
  75      * @return an {@code AudioFileFormat} object describing the audio file
  76      *         format
  77      * @throws UnsupportedAudioFileException if the URL does not point to valid
  78      *         audio file data recognized by the system
  79      * @throws IOException if an I/O exception occurs
  80      */
  81     public abstract AudioFileFormat getAudioFileFormat(URL url)
  82             throws UnsupportedAudioFileException, IOException;
  83 
  84     /**
  85      * Obtains the audio file format of the {@code File} provided.
  86      * The {@code File} must point to valid audio file data.
  87      *
  88      * @param  file the {@code File} from which file format information
  89      *         should be extracted
  90      * @return an {@code AudioFileFormat} object describing the audio file
  91      *         format
  92      * @throws UnsupportedAudioFileException if the {@code File} does not point
  93      *         to valid audio file data recognized by the system
  94      * @throws IOException if an I/O exception occurs
  95      */
  96     public abstract AudioFileFormat getAudioFileFormat(File file)
  97             throws UnsupportedAudioFileException, IOException;
  98 
  99     /**
 100      * Obtains an audio input stream from the input stream provided. The stream
 101      * must point to valid audio file data. In general, audio file readers may
 102      * need to read some data from the stream before determining whether they
 103      * support it. These parsers must be able to mark the stream, read enough
 104      * data to determine whether they support the stream, and, if not, reset the
 105      * stream's read pointer to its original position. If the input stream does
 106      * not support this, this method may fail with an {@code IOException}.
 107      *
 108      * @param  stream the input stream from which the {@code AudioInputStream}
 109      *         should be constructed
 110      * @return an {@code AudioInputStream} object based on the audio file data
 111      *         contained in the input stream.
 112      * @throws UnsupportedAudioFileException if the stream does not point to
 113      *         valid audio file data recognized by the system
 114      * @throws IOException if an I/O exception occurs
 115      * @see InputStream#markSupported
 116      * @see InputStream#mark
 117      */
 118     public abstract AudioInputStream getAudioInputStream(InputStream stream)
 119             throws UnsupportedAudioFileException, IOException;
 120 
 121     /**
 122      * Obtains an audio input stream from the URL provided. The URL must point
 123      * to valid audio file data.
 124      *
 125      * @param  url the URL for which the {@code AudioInputStream} should be
 126      *         constructed
 127      * @return an {@code AudioInputStream} object based on the audio file data
 128      *         pointed to by the URL
 129      * @throws UnsupportedAudioFileException if the URL does not point to valid
 130      *         audio file data recognized by the system
 131      * @throws IOException if an I/O exception occurs
 132      */
 133     public abstract AudioInputStream getAudioInputStream(URL url)
 134             throws UnsupportedAudioFileException, IOException;
 135 
 136     /**
 137      * Obtains an audio input stream from the {@code File} provided.
 138      * The {@code File} must point to valid audio file data.
 139      *
 140      * @param  file the {@code File} for which the {@code AudioInputStream}
 141      *         should be constructed
 142      * @return an {@code AudioInputStream} object based on the audio file data
 143      *         pointed to by the File
 144      * @throws UnsupportedAudioFileException if the {@code File} does not point
 145      *         to valid audio file data recognized by the system
 146      * @throws IOException if an I/O exception occurs
 147      */
 148     public abstract AudioInputStream getAudioInputStream(File file)
 149             throws UnsupportedAudioFileException, IOException;
 150 }