Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/sampled/spi/AudioFileWriter/AUwithULAW.java
41159 views
1
/*
2
* Copyright (c) 2002, 2016, 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
import java.io.ByteArrayInputStream;
25
import java.io.ByteArrayOutputStream;
26
import java.io.InputStream;
27
28
import javax.sound.sampled.AudioFileFormat;
29
import javax.sound.sampled.AudioFormat;
30
import javax.sound.sampled.AudioInputStream;
31
import javax.sound.sampled.AudioSystem;
32
33
/**
34
* @test
35
* @bug 4391108
36
* @summary Writing au files with ulaw encoding is broken
37
*/
38
public class AUwithULAW {
39
public static void main(String args[]) throws Exception {
40
System.out.println();
41
System.out.println();
42
System.out.println("4391108: Writing au files with ulaw encoding is broken");
43
byte[] fakedata=new byte[1234];
44
InputStream is = new ByteArrayInputStream(fakedata);
45
AudioFormat inFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, 8000, false);
46
47
AudioInputStream ais = new AudioInputStream(is, inFormat, fakedata.length);
48
49
ByteArrayOutputStream out = new ByteArrayOutputStream(1500);
50
System.out.println(" ulaw data will be written as AU to stream...");
51
int t = AudioSystem.write(ais, AudioFileFormat.Type.AU, out);
52
byte[] writtenData = out.toByteArray();
53
is = new ByteArrayInputStream(writtenData);
54
System.out.println(" Get AudioFileFormat of written file");
55
AudioFileFormat fileformat = AudioSystem.getAudioFileFormat(is);
56
AudioFileFormat.Type type = fileformat.getType();
57
System.out.println(" The file format type: "+type);
58
if (fileformat.getFrameLength()!=fakedata.length
59
&& fileformat.getFrameLength()!=AudioSystem.NOT_SPECIFIED) {
60
throw new Exception("The written file's frame length is "+fileformat.getFrameLength()+" but should be "+fakedata.length+" !");
61
}
62
ais = AudioSystem.getAudioInputStream(is);
63
System.out.println(" Got Stream with format: "+ais.getFormat());
64
System.out.println(" test passed.");
65
}
66
}
67
68