author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
32663
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
1 |
/* |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
4 |
* |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
8 |
* |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
14 |
* |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
18 |
* |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
21 |
* questions. |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
22 |
*/ |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
23 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
24 |
import java.io.ByteArrayInputStream; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
25 |
import java.io.IOException; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
26 |
import java.io.InputStream; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
27 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
28 |
import javax.sound.sampled.AudioSystem; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
29 |
import javax.sound.sampled.UnsupportedAudioFileException; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
30 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
31 |
/** |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
32 |
* @test |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
33 |
* @bug 8133677 |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
34 |
* @summary Subsequent read from the same stream should work |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
35 |
*/ |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
36 |
public final class RepeatedFormatReader { |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
37 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
38 |
// Stubs |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
39 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
40 |
private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
41 |
0, 0, 0, 6, // read header length |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
42 |
0, 0, // type |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
43 |
0, 0, // numtracks |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
44 |
0, 1, // timing |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
45 |
}; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
46 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
47 |
private static byte[] headerAU = {0x2e, 0x73, 0x6e, 0x64, // AU_SUN_MAGIC |
41394 | 48 |
0, 0, 0, 24, // headerSize |
32663
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
49 |
0, 0, 0, 0, // dataSize |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
50 |
0, 0, 0, 1, // encoding |
41394 | 51 |
0, 0, 0, 1, // sampleRate |
32663
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
52 |
0, 0, 0, 1 // channels |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
53 |
}; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
54 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
55 |
private static byte[] headerWAV = {0x52, 0x49, 0x46, 0x46, // RIFF_MAGIC |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
56 |
1, 1, 1, 1, // fileLength |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
57 |
0x57, 0x41, 0x56, 0x45, // waveMagic |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
58 |
0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
59 |
3, 0, 0, 0, // length |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
60 |
1, 0, // wav_type WAVE_FORMAT_PCM |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
61 |
0, 1, // channels |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
62 |
0, 0, 0, 0, // sampleRate |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
63 |
0, 0, 0, 0, // avgBytesPerSec |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
64 |
0, 0, // blockAlign |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
65 |
1, 0, // sampleSizeInBits |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
66 |
0x64, 0x61, 0x74, 0x61, // DATA_MAGIC |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
67 |
0, 0, 0, 0, // dataLength |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
68 |
}; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
69 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
70 |
private static final byte[][] data = {headerMIDI, headerAU, headerWAV}; |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
71 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
72 |
public static void main(final String[] args) |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
73 |
throws IOException, UnsupportedAudioFileException { |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
74 |
for (final byte[] bytes : data) { |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
75 |
test(bytes); |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
76 |
} |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
77 |
} |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
78 |
|
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
79 |
private static void test(final byte[] buffer) |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
80 |
throws IOException, UnsupportedAudioFileException { |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
81 |
final InputStream is = new ByteArrayInputStream(buffer); |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
82 |
for (int i = 0; i < 10; ++i) { |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
83 |
AudioSystem.getAudioFileFormat(is); |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
84 |
} |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
85 |
} |
1279321775f1
8133677: Specification of AudioFileReader should be clarifed
serb
parents:
diff
changeset
|
86 |
} |