Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/SF2SoundbankReader/TestGetSoundbankInputStream2.java
38862 views
/*1* Copyright (c) 2007, 2013, 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 SF2SoundbankReader getSoundbank(InputStream) method using25very bad InputStream which can only read 1 byte at time */2627import java.io.BufferedInputStream;28import java.io.File;29import java.io.FileInputStream;30import java.io.IOException;31import java.io.InputStream;3233import javax.sound.midi.Patch;34import javax.sound.midi.Soundbank;3536import com.sun.media.sound.SF2SoundbankReader;3738public class TestGetSoundbankInputStream2 {3940private static class BadInputStream extends InputStream41{4243InputStream is;4445public BadInputStream(InputStream is)46{47this.is = is;48}4950public int read() throws IOException {51return is.read();52}5354public int read(byte[] b, int off, int len) throws IOException {55if(len > 1) len = 1;56return is.read(b, off, len);57}5859public int read(byte[] b) throws IOException {60return read(b, 0, b.length);61}6263public long skip(long n) throws IOException {64if(n > 1) n = 1;65return is.skip(n);66}6768public int available() throws IOException {69int avail = is.available();70if(avail > 1) avail = 1;71return avail;72}7374public void close() throws IOException {75is.close();76}7778public synchronized void mark(int readlimit) {79is.mark(readlimit);80}8182public boolean markSupported() {83return is.markSupported();84}8586public synchronized void reset() throws IOException {87is.reset();88}8990}9192private static void assertTrue(boolean value) throws Exception93{94if(!value)95throw new RuntimeException("assertTrue fails!");96}9798public static void main(String[] args) throws Exception {99File file = new File(System.getProperty("test.src", "."), "ding.sf2");100FileInputStream fis = new FileInputStream(file);101BufferedInputStream bis = new BufferedInputStream(fis);102try103{104InputStream badis = new BadInputStream(bis);105Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis);106assertTrue(sf2.getInstruments().length == 1);107Patch patch = sf2.getInstruments()[0].getPatch();108assertTrue(patch.getProgram() == 0);109assertTrue(patch.getBank() == 0);110}111finally112{113bis.close();114}115}116}117118119