Back to project page BLE-MIDI-for-Android.
The source code is released under:
Apache License
If you think the Android project BLE-MIDI-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package jp.kshoji.blemidi.util; // w w w . j a va 2 s .com import java.io.ByteArrayOutputStream; /** * {@link java.io.ByteArrayOutputStream} that can reset without memory leak. * * @author K.Shoji */ public final class ReusableByteArrayOutputStream extends ByteArrayOutputStream { private static final int DEFAULT_BUFFER_LIMIT = 1024; private final byte[] fixedSizeBuffer; /** * Construct instance * * @param size the initial size of the stream */ public ReusableByteArrayOutputStream(int size) { super(size); fixedSizeBuffer = new byte[size]; this.buf = fixedSizeBuffer; } /** * Construct default instance, maximum buffer size is 1024 bytes. */ public ReusableByteArrayOutputStream() { this(DEFAULT_BUFFER_LIMIT); } @Override public synchronized void reset() { super.reset(); // reset buffer size when the buffer has been extended if (this.buf.length > fixedSizeBuffer.length) { this.buf = fixedSizeBuffer; } } }