Path: blob/master/test/jdk/javax/sound/sampled/spi/AudioFileReader/AuZeroLength.java
40527 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.File;25import java.io.FileInputStream;26import java.io.InputStream;2728import javax.sound.sampled.AudioFileFormat;29import javax.sound.sampled.AudioSystem;3031/**32* @test33* @bug 462966934* @summary AU file reader: problems with empty files35*/36public class AuZeroLength {3738public static String getString(byte b) {39//String res = Integer.toHexString(b & 0xFF).toUpperCase();40//while (res.length()<2) res="0"+res;41//return res;42return String.valueOf(b);43}444546public static void printFile(String filename) throws Exception {47File file = new File(filename);48FileInputStream fis = new FileInputStream(file);49byte[] data = new byte[(int) file.length()];50fis.read(data);51String s = "";52for (int i=0; i<data.length; i++) {53s+=getString(data[i])+", ";54if (s.length()>72) {55System.out.println(s);56s="";57}58}59System.out.println(s);60}6162public static void test(byte[] file) throws Exception {63InputStream inputStream = new ByteArrayInputStream(file);64AudioFileFormat aff = AudioSystem.getAudioFileFormat(inputStream);6566if (aff.getFrameLength() != 0) {67throw new Exception("File length is "+aff.getFrameLength()+" instead of 0. test FAILED");68}69System.out.println(aff.getType()+" file length is 0.");70}7172public static void main(String[] args) throws Exception {73test(ZERO_AU);74test(ZERO_WAV);75test(ZERO_AIFF);7677System.out.println("Test passed.");78}7980public static byte[] ZERO_AU = {8146, 115, 110, 100, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, -84, 68, 0,820, 0, 1, 116, 101, 115, 116, 46, 119, 97, 11883};8485public static byte[] ZERO_WAV = {8682, 73, 70, 70, 36, 0, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32, 16, 0, 0,870, 1, 0, 1, 0, 68, -84, 0, 0, -120, 88, 1, 0, 2, 0, 16, 0, 100, 97, 116,8897, 0, 0, 0, 089};9091public static byte[] ZERO_AIFF = {9270, 79, 82, 77, 0, 0, 0, 46, 65, 73, 70, 70, 67, 79, 77, 77, 0, 0, 0, 18,930, 1, 0, 0, 0, 0, 0, 16, 64, 14, -84, 68, 0, 0, 0, 0, 0, 0, 83, 83, 78, 68,940, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 095};9697}9899100