893N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
893N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
893N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
893N/A * or visit www.oracle.com if you need additional information or have any
893N/A * questions.
893N/A */
893N/A
893N/A/* @test
893N/A @summary Test DLSSoundbankReader getSoundbank(InputStream) method using
893N/A very bad InputStream which can only read 1 byte at time */
893N/A
893N/Aimport java.io.BufferedInputStream;
893N/Aimport java.io.File;
893N/Aimport java.io.FileInputStream;
893N/Aimport java.io.IOException;
893N/Aimport java.io.InputStream;
893N/A
893N/Aimport javax.sound.midi.Patch;
893N/Aimport javax.sound.midi.Soundbank;
893N/A
893N/Aimport com.sun.media.sound.DLSSoundbankReader;
893N/A
893N/Apublic class TestGetSoundbankInputStream2 {
893N/A
893N/A private static class BadInputStream extends InputStream
893N/A {
893N/A
893N/A InputStream is;
893N/A
893N/A public BadInputStream(InputStream is)
893N/A {
893N/A this.is = is;
893N/A }
893N/A
893N/A public int read() throws IOException {
893N/A return is.read();
893N/A }
893N/A
893N/A public int read(byte[] b, int off, int len) throws IOException {
893N/A if(len > 1) len = 1;
893N/A return is.read(b, off, len);
893N/A }
893N/A
893N/A public int read(byte[] b) throws IOException {
893N/A return read(b, 0, b.length);
893N/A }
893N/A
893N/A public long skip(long n) throws IOException {
893N/A if(n > 1) n = 1;
893N/A return is.skip(n);
893N/A }
893N/A
893N/A public int available() throws IOException {
893N/A int avail = is.available();
893N/A if(avail > 1) avail = 1;
893N/A return avail;
893N/A }
893N/A
893N/A public void close() throws IOException {
893N/A is.close();
893N/A }
893N/A
893N/A public synchronized void mark(int readlimit) {
is.mark(readlimit);
}
public boolean markSupported() {
return is.markSupported();
}
public synchronized void reset() throws IOException {
is.reset();
}
}
private static void assertTrue(boolean value) throws Exception
{
if(!value)
throw new RuntimeException("assertTrue fails!");
}
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("test.src", "."), "ding.dls");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
try
{
InputStream badis = new BadInputStream(bis);
Soundbank dls = new DLSSoundbankReader().getSoundbank(badis);
assertTrue(dls.getInstruments().length == 1);
Patch patch = dls.getInstruments()[0].getPatch();
assertTrue(patch.getProgram() == 0);
assertTrue(patch.getBank() == 0);
}
finally
{
bis.close();
}
}
}