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