Path: blob/master/test/jdk/javax/sound/midi/Gervill/ModelByteBuffer/GetInputStream.java
41159 views
/*1* Copyright (c) 2007, 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*/2223/* @test24@summary Test ModelByteBuffer getInputStream method25@modules java.desktop/com.sun.media.sound26*/2728import java.io.File;29import java.io.FileOutputStream;30import java.io.InputStream;31import java.nio.file.Files;32import java.nio.file.Paths;3334import javax.sound.sampled.*;3536import com.sun.media.sound.*;3738public class GetInputStream {3940static float[] testarray;41static byte[] test_byte_array;42static File test_file;43static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);4445static void setUp() throws Exception {46testarray = new float[1024];47for (int i = 0; i < 1024; i++) {48double ii = i / 1024.0;49ii = ii * ii;50testarray[i] = (float)Math.sin(10*ii*2*Math.PI);51testarray[i] += (float)Math.sin(1.731 + 2*ii*2*Math.PI);52testarray[i] += (float)Math.sin(0.231 + 6.3*ii*2*Math.PI);53testarray[i] *= 0.3;54}55test_byte_array = new byte[testarray.length*2];56AudioFloatConverter.getConverter(format).toByteArray(testarray, test_byte_array);57test_file = File.createTempFile("test", ".raw");58try (FileOutputStream fos = new FileOutputStream(test_file)) {59fos.write(test_byte_array);60}61}6263static void tearDown() throws Exception {64Files.delete(Paths.get(test_file.getAbsolutePath()));65}6667public static void main(String[] args) throws Exception {68try69{70setUp();7172for (int i = 0; i < 2; i++) {73ModelByteBuffer buff;74if(i == 0)75buff = new ModelByteBuffer(test_file);76else77buff = new ModelByteBuffer(test_byte_array);7879byte[] b = new byte[test_byte_array.length];80try (InputStream is = buff.getInputStream()) {81is.read(b);82}83for (int j = 0; j < b.length; j++)84if(b[i] != test_byte_array[i])85throw new RuntimeException("Byte array compare fails!");86}87}88finally89{90tearDown();91}92}9394}959697