28Aug/080
IOException when loading a sound/midi from a JAR/ZIP archive
I have a MIDI file in a JAR archive. If I try to play it with the Sequencer class, I got an exception: "java.io.IOException: mark/reset not supported". I've found this related bug. I don't like workarounds (all bugs must die), but I developed this one:
public static InputStream loadStream(InputStream in) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int c; while ((c = in.read(buf)) != -1) { bos.write(buf, 0, c); } return new ByteArrayInputStream(bos.toByteArray()); }
With this method, I encapsulate the "unresetable" stream into a "resetable" ByteArrayInputStream.