/* * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
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
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet)
¤
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.