private static boolean writeOutStream(ResampleContext rCtx, OutputStream fpo, int nsmplwrt, int dbps, boolean isLast) throws IOException {
        int nch = rCtx.twopass ? rCtx.nch : rCtx.dnch;

        if (!rCtx.init) {
            if (isLast) {
                if ((double) rCtx.sumread * rCtx.dfrq / rCtx.sfrq + 2 > rCtx.sumwrite + nsmplwrt) {
                    fpo.write(rCtx.rawoutbuf, 0, dbps * nch * nsmplwrt);
                    rCtx.sumwrite += nsmplwrt;
                } else {
                    int limitData = (int) (dbps * nch * (Math.floor((double) rCtx.sumread * rCtx.dfrq / rCtx.sfrq) + 2 - rCtx.sumwrite));
                    if (limitData > 0) {
                        fpo.write(rCtx.rawoutbuf, 0, limitData);
                    }
                    reset(rCtx);
                    return true;
                }
            } else {
                fpo.write(rCtx.rawoutbuf, 0, dbps * nch * nsmplwrt);
                rCtx.sumwrite += nsmplwrt;
            }
        } else {
            if (nsmplwrt < rCtx.delay) {
                rCtx.delay -= nsmplwrt;
            } else {
                if (isLast) {
                    if ((double) rCtx.sumread * rCtx.dfrq / rCtx.sfrq + 2 > rCtx.sumwrite + nsmplwrt - rCtx.delay) {
                        fpo.write(rCtx.rawoutbuf, dbps * nch * rCtx.delay, dbps * nch * (nsmplwrt - rCtx.delay));
                        rCtx.sumwrite += nsmplwrt - rCtx.delay;
                    } else {
                        fpo.write(rCtx.rawoutbuf, dbps * nch * rCtx.delay, (int) (dbps * nch * (Math.floor((double) rCtx.sumread * rCtx.dfrq / rCtx.sfrq) + 2 - rCtx.sumwrite - rCtx.delay)));
                        reset(rCtx);
                        return true;
                    }
                } else {
                    fpo.write(rCtx.rawoutbuf, dbps * nch * rCtx.delay, dbps * nch * (nsmplwrt - rCtx.delay));
                    rCtx.sumwrite += nsmplwrt - rCtx.delay;
                    rCtx.init = false;
                }
            }
        }
        return false;
    }