Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/sampled/FileReader/ReadersExceptions.java
38855 views
1
/*
2
* Copyright (c) 2013, 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.
8
*
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
25
import java.io.ByteArrayInputStream;
26
import java.io.IOException;
27
import java.io.InputStream;
28
29
import javax.sound.sampled.AudioSystem;
30
import javax.sound.sampled.UnsupportedAudioFileException;
31
32
/**
33
* @test
34
* @bug 7058662 7058666 7058672
35
* @author Sergey Bylokhov
36
*/
37
public final class ReadersExceptions {
38
39
// empty channels
40
static byte[] wrongAIFFCh =
41
{0x46, 0x4f, 0x52, 0x4d, // AiffFileFormat.AIFF_MAGIC
42
0, 0, 0, 0, // length
43
0, 0, 0, 0, // iffType
44
0x43, 0x4f, 0x4d, 0x4d, // chunkName
45
0, 0, 0, 100, // chunkLen
46
0, 0, // channels
47
0, 0, 0, 0, //
48
0, 10 // sampleSize
49
, 0, 0, 0, 0};
50
// empty sampleSize
51
static byte[] wrongAIFFSSL =
52
{0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
53
0, 0, 0, 0, // length
54
0, 0, 0, 0, // iffType
55
0x43, 0x4f, 0x4d, 0x4d, // chunkName
56
0, 0, 0, 100, // chunkLen
57
0, 10, // channels
58
0, 0, 0, 0, //
59
0, 0 // sampleSize
60
, 0, 0, 0, 0};
61
// big sampleSize
62
static byte[] wrongAIFFSSH =
63
{0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
64
0, 0, 0, 0, // length
65
0, 0, 0, 0, // iffType
66
0x43, 0x4f, 0x4d, 0x4d, // chunkName
67
0, 0, 0, 100, // chunkLen
68
0, 10, // channels
69
0, 0, 0, 0, //
70
0, 33 // sampleSize
71
, 0, 0, 0, 0};
72
// empty channels
73
static byte[] wrongAUCh =
74
{0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
75
0, 0, 0, 0, // headerSize
76
0, 0, 0, 0, // dataSize
77
0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
78
0, 0, 0, 0, // sampleRate
79
0, 0, 0, 0 // channels
80
};
81
// empty channels
82
static byte[] wrongWAVCh =
83
{0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
84
1, 1, 1, 1, // fileLength
85
0x57, 0x41, 0x56, 0x45, // waveMagic
86
0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
87
3, 0, 0, 0, // length
88
1, 0, // wav_type WAVE_FORMAT_PCM
89
0, 0, // channels
90
0, 0, 0, 0, // sampleRate
91
0, 0, 0, 0, // avgBytesPerSec
92
0, 0, // blockAlign
93
1, 0, // sampleSizeInBits
94
0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
95
0, 0, 0, 0, // dataLength
96
};
97
// empty sampleSizeInBits
98
static byte[] wrongWAVSSB =
99
{0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
100
1, 1, 1, 1, // fileLength
101
0x57, 0x41, 0x56, 0x45, // waveMagic
102
0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
103
3, 0, 0, 0, // length
104
1, 0, // wav_type WAVE_FORMAT_PCM
105
1, 0, // channels
106
0, 0, 0, 0, // sampleRate
107
0, 0, 0, 0, // avgBytesPerSec
108
0, 0, // blockAlign
109
0, 0, // sampleSizeInBits
110
0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
111
0, 0, 0, 0, // dataLength
112
};
113
114
public static void main(final String[] args) throws IOException {
115
test(wrongAIFFCh);
116
test(wrongAIFFSSL);
117
test(wrongAIFFSSH);
118
test(wrongAUCh);
119
test(wrongWAVCh);
120
test(wrongWAVSSB);
121
}
122
123
private static void test(final byte[] buffer) throws IOException {
124
final InputStream is = new ByteArrayInputStream(buffer);
125
try {
126
AudioSystem.getAudioFileFormat(is);
127
} catch (UnsupportedAudioFileException ignored) {
128
// Expected.
129
return;
130
}
131
throw new RuntimeException("Test Failed");
132
}
133
}
134
135