< prev index next >

test/javax/sound/sampled/AudioInputStream/FrameLengthAfterConversion.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.ByteArrayInputStream;
  25 import java.io.ByteArrayOutputStream;
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.io.InputStream;


  29 import java.util.ArrayList;
  30 import java.util.List;
  31 
  32 import javax.sound.sampled.AudioFileFormat;
  33 import javax.sound.sampled.AudioFormat;
  34 import javax.sound.sampled.AudioInputStream;
  35 import javax.sound.sampled.AudioSystem;
  36 import javax.sound.sampled.UnsupportedAudioFileException;
  37 import javax.sound.sampled.spi.AudioFileWriter;
  38 import javax.sound.sampled.spi.FormatConversionProvider;
  39 
  40 import static java.util.ServiceLoader.load;
  41 import static javax.sound.sampled.AudioFileFormat.Type.AIFC;
  42 import static javax.sound.sampled.AudioFileFormat.Type.AIFF;
  43 import static javax.sound.sampled.AudioFileFormat.Type.AU;
  44 import static javax.sound.sampled.AudioFileFormat.Type.SND;
  45 import static javax.sound.sampled.AudioFileFormat.Type.WAVE;
  46 import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
  47 
  48 /**


 145                     out.toByteArray());
 146             validate(AudioSystem.getAudioInputStream(input).getFrameLength());
 147         } catch (IllegalArgumentException | UnsupportedAudioFileException
 148                 | IOException ignored) {
 149         }
 150     }
 151 
 152     /**
 153      * Verifies the frame length after the stream was saved/read to/from file.
 154      */
 155     private static void testAfterSaveToFile(final AudioFileWriter afw,
 156                                             final AudioFileFormat.Type type,
 157                                             AudioInputStream ais) {
 158         try {
 159             final File temp = File.createTempFile("sound", ".tmp");
 160             temp.deleteOnExit();
 161             afw.write(ais, type, temp);
 162             ais = AudioSystem.getAudioInputStream(temp);
 163             final long frameLength = ais.getFrameLength();
 164             ais.close();
 165             temp.delete();
 166             validate(frameLength);
 167         } catch (IllegalArgumentException | UnsupportedAudioFileException
 168                 | IOException ignored) {
 169         }
 170     }
 171 
 172     /**
 173      * Verifies the frame length after the stream was converted to other
 174      * stream.
 175      *
 176      * @see FormatConversionProvider#getAudioInputStream(AudioFormat,
 177      * AudioInputStream)
 178      */
 179     private static void testAfterConversion(final FormatConversionProvider fcp,
 180                                             final AudioFormat to,
 181                                             final AudioInputStream ais) {
 182         if (fcp.isConversionSupported(to, ais.getFormat())) {
 183             validate(fcp.getAudioInputStream(to, ais).getFrameLength());
 184         }
 185     }




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.ByteArrayInputStream;
  25 import java.io.ByteArrayOutputStream;
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.nio.file.Files;
  30 import java.nio.file.Paths;
  31 import java.util.ArrayList;
  32 import java.util.List;
  33 
  34 import javax.sound.sampled.AudioFileFormat;
  35 import javax.sound.sampled.AudioFormat;
  36 import javax.sound.sampled.AudioInputStream;
  37 import javax.sound.sampled.AudioSystem;
  38 import javax.sound.sampled.UnsupportedAudioFileException;
  39 import javax.sound.sampled.spi.AudioFileWriter;
  40 import javax.sound.sampled.spi.FormatConversionProvider;
  41 
  42 import static java.util.ServiceLoader.load;
  43 import static javax.sound.sampled.AudioFileFormat.Type.AIFC;
  44 import static javax.sound.sampled.AudioFileFormat.Type.AIFF;
  45 import static javax.sound.sampled.AudioFileFormat.Type.AU;
  46 import static javax.sound.sampled.AudioFileFormat.Type.SND;
  47 import static javax.sound.sampled.AudioFileFormat.Type.WAVE;
  48 import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
  49 
  50 /**


 147                     out.toByteArray());
 148             validate(AudioSystem.getAudioInputStream(input).getFrameLength());
 149         } catch (IllegalArgumentException | UnsupportedAudioFileException
 150                 | IOException ignored) {
 151         }
 152     }
 153 
 154     /**
 155      * Verifies the frame length after the stream was saved/read to/from file.
 156      */
 157     private static void testAfterSaveToFile(final AudioFileWriter afw,
 158                                             final AudioFileFormat.Type type,
 159                                             AudioInputStream ais) {
 160         try {
 161             final File temp = File.createTempFile("sound", ".tmp");
 162             temp.deleteOnExit();
 163             afw.write(ais, type, temp);
 164             ais = AudioSystem.getAudioInputStream(temp);
 165             final long frameLength = ais.getFrameLength();
 166             ais.close();
 167             Files.delete(Paths.get(temp.getAbsolutePath()));
 168             validate(frameLength);
 169         } catch (IllegalArgumentException | UnsupportedAudioFileException
 170                 | IOException ignored) {
 171         }
 172     }
 173 
 174     /**
 175      * Verifies the frame length after the stream was converted to other
 176      * stream.
 177      *
 178      * @see FormatConversionProvider#getAudioInputStream(AudioFormat,
 179      * AudioInputStream)
 180      */
 181     private static void testAfterConversion(final FormatConversionProvider fcp,
 182                                             final AudioFormat to,
 183                                             final AudioInputStream ais) {
 184         if (fcp.isConversionSupported(to, ais.getFormat())) {
 185             validate(fcp.getAudioInputStream(to, ais).getFrameLength());
 186         }
 187     }


< prev index next >