InputStream is = new ByteArrayInputStream(midifile); // create a buffered input stream that seems // to be on an unfortunate boundary for the // 1.4.2 SMF parser implementation
is = new ChunkInputStream(is, 32);
Sequence sequence = MidiSystem.getSequence(is);
long duration = sequence.getMicrosecondLength() / 10000;
System.out.println("Duration: "+duration+" deciseconds ");
// the test is passed if no exception thrown
System.out.println("Test passed");
}
/* an input stream that always returns data in chunks */ class ChunkInputStream extends FilterInputStream { int chunkSize; int p = 0; // position
public ChunkInputStream(InputStream is, int chunkSize) { super(is); this.chunkSize = chunkSize;
}
// override to increase counter publicint read() throws IOException { int ret = super.read(); if (ret >= 0) {
p++;
} return ret;
}
// override to make sure that read(byte[], int, int) is used publicint read(byte[] b) throws IOException { return read(b, 0, b.length);
}
// override to split the data in chunks publicint read(byte[] b, int off, int len) throws IOException { // if we would pass a chunk boundary, // only return up to the chunk boundary if ( (p / chunkSize) < ( (p+len) / chunkSize)) { // p+len is in the next chunk
len -= ((p+len) % chunkSize);
} int ret = super.read(b, off, len); if (ret >= 0) {
p += ret;
} return ret;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.