Path: blob/master/test/jdk/javax/sound/sampled/spi/AudioFileReader/RepeatedFormatReader.java
40527 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;24import java.io.IOException;25import java.io.InputStream;2627import javax.sound.sampled.AudioSystem;28import javax.sound.sampled.UnsupportedAudioFileException;2930/**31* @test32* @bug 813367733* @summary Subsequent read from the same stream should work34*/35public final class RepeatedFormatReader {3637// Stubs3839private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd400, 0, 0, 6, // read header length410, 0, // type420, 0, // numtracks430, 1, // timing44};4546private static byte[] headerAU = {0x2e, 0x73, 0x6e, 0x64, // AU_SUN_MAGIC470, 0, 0, 24, // headerSize480, 0, 0, 0, // dataSize490, 0, 0, 1, // encoding500, 0, 0, 1, // sampleRate510, 0, 0, 1 // channels52};5354private static byte[] headerWAV = {0x52, 0x49, 0x46, 0x46, // RIFF_MAGIC551, 1, 1, 1, // fileLength560x57, 0x41, 0x56, 0x45, // waveMagic570x66, 0x6d, 0x74, 0x20, // FMT_MAGIC583, 0, 0, 0, // length591, 0, // wav_type WAVE_FORMAT_PCM600, 1, // channels610, 0, 0, 0, // sampleRate620, 0, 0, 0, // avgBytesPerSec630, 0, // blockAlign641, 0, // sampleSizeInBits650x64, 0x61, 0x74, 0x61, // DATA_MAGIC660, 0, 0, 0, // dataLength67};6869private static final byte[][] data = {headerMIDI, headerAU, headerWAV};7071public static void main(final String[] args)72throws IOException, UnsupportedAudioFileException {73for (final byte[] bytes : data) {74test(bytes);75}76}7778private static void test(final byte[] buffer)79throws IOException, UnsupportedAudioFileException {80final InputStream is = new ByteArrayInputStream(buffer);81for (int i = 0; i < 10; ++i) {82AudioSystem.getAudioFileFormat(is);83}84}85}868788