Path: blob/master/test/jdk/javax/sound/midi/Soundbanks/GetSoundBankIOException.java
41154 views
/*1* Copyright (c) 2003, 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.File;24import java.io.IOException;25import java.io.InputStream;2627import javax.sound.midi.InvalidMidiDataException;28import javax.sound.midi.MidiSystem;2930/**31* @test32* @bug 462981033* @summary MidiSystem.getSoundbank() throws unexpected IOException34*/35public class GetSoundBankIOException {3637public static void main(String args[]) throws Exception {38boolean failed = false;39try {40String filename = "GetSoundBankIOException.java";41System.out.println("Opening "+filename+" as soundbank...");42File midiFile = new File(System.getProperty("test.src", "."), filename);43MidiSystem.getSoundbank(midiFile);44//Soundbank sBank = MidiSystem.getSoundbank(new NonMarkableIS());45System.err.println("InvalidMidiDataException was not thrown!");46failed = true;47} catch (InvalidMidiDataException invMidiEx) {48System.err.println("InvalidMidiDataException was thrown. OK.");49} catch (IOException ioEx) {50System.err.println("Unexpected IOException was caught!");51System.err.println(ioEx.getMessage());52ioEx.printStackTrace();53failed = true;54}5556if (failed) throw new Exception("Test FAILED!");57System.out.println("Test passed.");58}5960private static class NonMarkableIS extends InputStream {61int counter = 0;6263public NonMarkableIS() {64}6566public int read() throws IOException {67if (counter > 1000) return -1;68return (++counter) % 256;69}7071public synchronized void mark(int readlimit) {72System.out.println("Called mark with readlimit= "+readlimit);73}7475public synchronized void reset() throws IOException {76throw new IOException("mark/reset not supported");77}7879public boolean markSupported() {80return false;81}8283}84}858687