author | serb |
Wed, 04 May 2016 01:03:46 +0300 | |
changeset 38399 | bd91ce346b5b |
parent 36918 | 7f6b24ece62a |
permissions | -rw-r--r-- |
36918
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
1 |
/* |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
4 |
* |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
8 |
* |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
14 |
* |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
18 |
* |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
21 |
* questions. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
22 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
23 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
24 |
import java.io.ByteArrayInputStream; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
25 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
26 |
import javax.sound.sampled.AudioFileFormat; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
27 |
import javax.sound.sampled.AudioFormat; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
28 |
import javax.sound.sampled.AudioInputStream; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
29 |
import javax.sound.sampled.AudioSystem; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
30 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
31 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
32 |
* @test |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
33 |
* @bug 8132782 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
34 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
35 |
public final class RecognizeHugeWaveExtFiles { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
36 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
37 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
38 |
* The maximum size in bytes per WAVE specification. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
39 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
40 |
private static final /*unsigned int */ long MAX_UNSIGNED_INT = 0xffffffffL; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
41 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
42 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
43 |
* The supported wave ext format and sample size in bits. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
44 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
45 |
private static final int[][] waveTypeBits = { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
46 |
{0xFFFE/*WAVE_FORMAT_EXTENSIBLE*/, 8} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
47 |
}; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
48 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
49 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
50 |
* The list of supported sample rates(stored as unsigned int). |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
51 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
52 |
private static final int[] sampleRates = { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
53 |
8000, 11025, 16000, 22050, 32000, 37800, 44056, 44100, 47250, 48000, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
54 |
50000, 50400, 88200, 96000, 176400, 192000, 352800, 2822400, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
55 |
5644800, Integer.MAX_VALUE |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
56 |
}; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
57 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
58 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
59 |
* The list of supported channels (stored as unsigned int). |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
60 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
61 |
private static final int[] channels = { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
62 |
1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
63 |
}; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
64 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
65 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
66 |
* The list of supported size of data (stored as unsigned int). |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
67 |
* <p> |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
68 |
* The {@code MAX_UNSIGNED_INT} is a maximum size. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
69 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
70 |
private static final long[] dataSizes = { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
71 |
0, 1, 2, 3, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
72 |
(long) Integer.MAX_VALUE + 1, MAX_UNSIGNED_INT - 1, MAX_UNSIGNED_INT |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
73 |
}; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
74 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
75 |
public static void main(final String[] args) throws Exception { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
76 |
for (final int[] type : waveTypeBits) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
77 |
for (final int sampleRate : sampleRates) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
78 |
for (final int channel : channels) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
79 |
for (final long dataSize : dataSizes) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
80 |
testAFF(type, sampleRate, channel, dataSize); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
81 |
testAIS(type, sampleRate, channel, dataSize); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
82 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
83 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
84 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
85 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
86 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
87 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
88 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
89 |
* Tests the {@code AudioFileFormat} fetched from the fake header. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
90 |
* <p> |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
91 |
* Note that the frameLength and byteLength are stored as int which means |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
92 |
* that {@code AudioFileFormat} will store the data above {@code MAX_INT} as |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
93 |
* NOT_SPECIFIED. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
94 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
95 |
private static void testAFF(final int[] type, final int rate, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
96 |
final int channel, final long size) |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
97 |
throws Exception { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
98 |
final byte[] header = createHeader(type, rate, channel, size); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
99 |
final ByteArrayInputStream fake = new ByteArrayInputStream(header); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
100 |
final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
101 |
final AudioFormat format = aff.getFormat(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
102 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
103 |
if (aff.getType() != AudioFileFormat.Type.WAVE) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
104 |
throw new RuntimeException("Error"); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
105 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
106 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
107 |
final long frameLength = size / format.getFrameSize(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
108 |
if (frameLength <= Integer.MAX_VALUE) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
109 |
if (aff.getFrameLength() != frameLength) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
110 |
System.err.println("Expected: " + frameLength); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
111 |
System.err.println("Actual: " + aff.getFrameLength()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
112 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
113 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
114 |
} else { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
115 |
if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
116 |
System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
117 |
System.err.println("Actual: " + aff.getFrameLength()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
118 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
119 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
120 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
121 |
validateFormat(type[1], rate, channel, aff.getFormat()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
122 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
123 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
124 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
125 |
* Tests the {@code AudioInputStream} fetched from the fake header. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
126 |
* <p> |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
127 |
* Note that the frameLength is stored as long which means that {@code |
38399
bd91ce346b5b
6729836: JavaSound treats large file sizes as negative and cannot read or skip
serb
parents:
36918
diff
changeset
|
128 |
* AudioInputStream} must store all possible data from wave file. |
36918
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
129 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
130 |
private static void testAIS(final int[] type, final int rate, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
131 |
final int channel, final long size) |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
132 |
throws Exception { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
133 |
final byte[] header = createHeader(type, rate, channel, size); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
134 |
final ByteArrayInputStream fake = new ByteArrayInputStream(header); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
135 |
final AudioInputStream ais = AudioSystem.getAudioInputStream(fake); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
136 |
final AudioFormat format = ais.getFormat(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
137 |
final long frameLength = size / format.getFrameSize(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
138 |
if (frameLength != ais.getFrameLength()) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
139 |
System.err.println("Expected: " + frameLength); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
140 |
System.err.println("Actual: " + ais.getFrameLength()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
141 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
142 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
143 |
if (ais.available() < 0) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
144 |
System.err.println("available should be >=0: " + ais.available()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
145 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
146 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
147 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
148 |
validateFormat(type[1], rate, channel, format); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
149 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
150 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
151 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
152 |
* Tests that format contains the same data as were provided to the fake |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
153 |
* stream. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
154 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
155 |
private static void validateFormat(final int bits, final int rate, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
156 |
final int channel, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
157 |
final AudioFormat format) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
158 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
159 |
if (Float.compare(format.getSampleRate(), rate) != 0) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
160 |
System.err.println("Expected: " + rate); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
161 |
System.err.println("Actual: " + format.getSampleRate()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
162 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
163 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
164 |
if (format.getChannels() != channel) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
165 |
System.err.println("Expected: " + channel); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
166 |
System.err.println("Actual: " + format.getChannels()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
167 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
168 |
} |
38399
bd91ce346b5b
6729836: JavaSound treats large file sizes as negative and cannot read or skip
serb
parents:
36918
diff
changeset
|
169 |
int frameSize = ((bits + 7) / 8) * channel; |
bd91ce346b5b
6729836: JavaSound treats large file sizes as negative and cannot read or skip
serb
parents:
36918
diff
changeset
|
170 |
if (format.getFrameSize() != frameSize) { |
bd91ce346b5b
6729836: JavaSound treats large file sizes as negative and cannot read or skip
serb
parents:
36918
diff
changeset
|
171 |
System.err.println("Expected: " + frameSize); |
36918
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
172 |
System.err.println("Actual: " + format.getFrameSize()); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
173 |
throw new RuntimeException(); |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
174 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
175 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
176 |
|
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
177 |
/** |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
178 |
* Creates the custom header of the WAVE file. It is expected that all |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
179 |
* passed data are supported. |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
180 |
*/ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
181 |
private static byte[] createHeader(final int[] type, final int rate, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
182 |
final int channel, final long size) { |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
183 |
final int frameSize = ((type[1] + 7) / 8) * channel; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
184 |
return new byte[]{ |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
185 |
// RIFF_MAGIC |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
186 |
0x52, 0x49, 0x46, 0x46, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
187 |
// fileLength |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
188 |
-1, -1, -1, -1, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
189 |
// waveMagic |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
190 |
0x57, 0x41, 0x56, 0x45, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
191 |
// FMT_MAGIC |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
192 |
0x66, 0x6d, 0x74, 0x20, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
193 |
// size |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
194 |
40, 0, 0, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
195 |
// wav_type WAVE_FORMAT_EXTENSIBLE |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
196 |
(byte) (type[0]), (byte) (type[0] >> 8), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
197 |
// channels |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
198 |
(byte) (channel), (byte) (channel >> 8), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
199 |
// samplerate |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
200 |
(byte) (rate), (byte) (rate >> 8), (byte) (rate >> 16), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
201 |
(byte) (rate >> 24), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
202 |
// framerate |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
203 |
1, 0, 0, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
204 |
// framesize |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
205 |
(byte) (frameSize), (byte) (frameSize >> 8), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
206 |
// bits |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
207 |
(byte) type[1], 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
208 |
// cbsize |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
209 |
22, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
210 |
// validBitsPerSample |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
211 |
8, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
212 |
// channelMask |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
213 |
0, 0, 0, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
214 |
// SUBTYPE_IEEE_FLOAT |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
215 |
// i1 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
216 |
0x3, 0x0, 0x0, 0x0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
217 |
//s1 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
218 |
0x0, 0x0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
219 |
//s2 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
220 |
0x10, 0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
221 |
//x1 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
222 |
(byte) 0x80, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
223 |
//x2 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
224 |
0x0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
225 |
//x3 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
226 |
0x0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
227 |
//x4 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
228 |
(byte) 0xaa, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
229 |
//x5 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
230 |
0x0, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
231 |
//x6 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
232 |
0x38, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
233 |
//x7 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
234 |
(byte) 0x9b, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
235 |
//x8 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
236 |
0x71, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
237 |
// DATA_MAGIC |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
238 |
0x64, 0x61, 0x74, 0x61, |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
239 |
// data size |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
240 |
(byte) (size), (byte) (size >> 8), (byte) (size >> 16), |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
241 |
(byte) (size >> 24) |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
242 |
// data |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
243 |
, 0, 0, 0, 0, 0 |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
244 |
}; |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
245 |
} |
7f6b24ece62a
8132782: RIFFReader does not support WAVE-Files greater than 2 GiB
serb
parents:
diff
changeset
|
246 |
} |