All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadinstitute.hellbender.utils.io.HardThresholdingOutputStream Maven / Gradle / Ivy

The newest version!
package org.broadinstitute.hellbender.utils.io;

import org.apache.commons.io.output.ThresholdingOutputStream;

import java.io.IOException;

/**
 * An output stream which stops at the threshold
 * instead of potentially triggering early.
 */
public abstract class HardThresholdingOutputStream extends ThresholdingOutputStream {
    protected HardThresholdingOutputStream(int threshold) {
        super(threshold);
    }

    @Override
    public void write(byte[] b) throws IOException {
        write(b, 0, b.length);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        int remaining = this.getThreshold() - (int)this.getByteCount();
        if (!isThresholdExceeded() && len > remaining) {
            super.write(b, off, remaining);
            super.write(b, off + remaining, len - remaining);
        } else {
            super.write(b, off, len);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy