Examples of BBucket


Examples of org.apache.tomcat.lite.io.BBucket

                }
                // input connection closed ?
                closeStreamOnEnd("Closed input");
                return;
            }
            BBucket rawBuf = rawReceiveBuffers.peekFirst();
            if (rawBuf == null) {
                return// need more data
            }

            if (!bodys.isContentDelimited()) {
                while (true) {
                    BBucket first = rawReceiveBuffers.popFirst();
                    if (first == null) {
                        break; // will go back to check if done.
                    } else {
                        received(body, first);
                    }
                }
            } else {

                if (bodys.contentLength >= 0 && bodys.remaining == 0) {
                    receiveDone(http, body, false);
                    return;
                }

                if (bodys.chunked && bodys.remaining == 0) {
                    int rc = NEED_MORE;
                    // TODO: simplify, use readLine()
                    while (rc == NEED_MORE) {
                        rc = rchunk.parseChunkHeader(rawReceiveBuffers);
                        if (rc == ERROR) {
                            http.abort("Chunk error");
                            receiveDone(http, body, true);
                            return;
                        } else if (rc == NEED_MORE) {
                            return;
                        }
                    }
                    if (rc == 0) { // last chunk
                        receiveDone(http, body, false);
                        return;
                    } else {
                        bodys.remaining = rc;
                    }
                }

                rawBuf = (BBucket) rawReceiveBuffers.peekFirst();
                if (rawBuf == null) {
                    return// need more data
                }


                if (bodys.remaining < rawBuf.remaining()) {
                    // To buffer has more data than we need.
                    int lenToConsume = (int) bodys.remaining;
                    BBucket sb = rawReceiveBuffers.popLen(lenToConsume);
                    received(body, sb);
                    //log.info("Queue received buffer " + this + " " + lenToConsume);
                    bodys.remaining = 0;
                } else {
                    BBucket first = rawReceiveBuffers.popFirst();
                    bodys.remaining -= first.remaining();
                    received(body, first);
                    //log.info("Queue full received buffer " + this + " RAW: " + rawReceiveBuffers);
                }
                if (bodys.contentLength >= 0 && bodys.remaining == 0) {
                    // Content-Length, all done
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

    }


    private boolean sendContentLen(BodyState bodys, IOBuffer body, IOBuffer out) throws IOException {
        while (true) {
            BBucket bucket = body.peekFirst();
            if (bucket == null) {
                break;
            }
            int len = bucket.remaining();
            if (len <= bodys.remaining) {
                bodys.remaining -= len;
                bucket = body.popFirst();
                out.queue(bucket);
            } else {
                // Write over the end of the buffer !
                log.severe("write more than Content-Length");
                len = (int) bodys.remaining;
                // data between position and limit
                bucket = body.popLen((int) bodys.remaining);
                out.queue(bucket);
                while (bucket != null) {
                    bucket = body.popFirst();
                    if (bucket != null) {
                        bucket.release();
                    }
                }

                // forced close
                //close();
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

        if (len > 0) {
            ByteBuffer sendChunkBuffer = chunk.prepareChunkHeader(len);
            bodys.remaining = len;
            out.queue(sendChunkBuffer);
            while (bodys.remaining > 0) {
                BBucket bc = body.popFirst();
                bodys.remaining -= bc.remaining();
                out.queue(bc);
            }
        }

        if (body.isClosedAndEmpty()) {
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

        return this;
    }

    void compress(IOBuffer in, IOBuffer out) throws IOException {
        init();
        BBucket bb = in.popFirst();

        while (bb != null) {
            // TODO: only the last one needs flush

            // TODO: size missmatches ?
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

        decompress(in, out, in.available());
    }

    void decompress(IOBuffer in, IOBuffer out, int len) throws IOException {
        init();
        BBucket bb = in.peekFirst();

        while (bb != null && len > 0) {
            dStream.next_in = bb.array();
            dStream.next_in_index = bb.position();
            int rd = Math.min(bb.remaining(), len);
            dStream.avail_in = rd;

            while (true) {
                ByteBuffer outB = out.getWriteBuffer();

                dStream.next_out = outB.array();
                dStream.next_out_index = outB.position();
                dStream.avail_out = outB.remaining();

                int err = dStream.inflate(JZlib.Z_SYNC_FLUSH);
                if (err == JZlib.Z_NEED_DICT && dict != null) {
                    // dStream.adler has the dict id - not sure how to check
                    if (dictId != 0 && dStream.adler != dictId) {
                        throw new IOException("Invalid dictionary");
                    }
                    if (dictId == 0) {
                        // initDict should pass a real dict id.
                        System.err.println("Missing dict ID: " + dStream.adler);
                    }
                    dStream.inflateSetDictionary(dict, dict.length);
                    err = dStream.inflate(JZlib.Z_SYNC_FLUSH);
                }
                outB.position(dStream.next_out_index);
                out.releaseWriteBuffer(1);

                if (err == JZlib.Z_STREAM_END) {
                    err = dStream.inflateEnd();
                    out.close();
                    check(err, dStream);
                    // move in back, not consummed
                    bb.position(dStream.next_in_index);
                    return;
                }
                check(err, dStream);

                if (dStream.avail_out > 0 || dStream.avail_in == 0) {
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

        case 400:
            return st_400;
        case 404:
            return st_404;
        }
        BBucket bb = stats.get(status);
        if (bb == null) {
            return st_unknown;
        }
        return bb;
    }
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

                net.startSending();
                return;
            }
            int len = currentInFrame.length;
            while (len > 0) {
                BBucket bb = iob.peekFirst();
                if (bb == null) {
                    // we should have all data
                    abort("Unexpected short read");
                    return;
                }
                if (len > bb.remaining()) {
                    ch.getIn().append(bb);
                    len -= bb.remaining();
                    bb.position(bb.limit());
                } else {
                    ch.getIn().append(bb, len);
                    bb.position(bb.position() + len);
                    len = 0;
                }
            }
            ch.sendHandleReceivedCallback();
View Full Code Here

Examples of org.apache.tomcat.lite.io.BBucket

   }

    public int doRead(BBuffer chunk)
            throws IOException {
        checkRelease();
        BBucket next = null;
        while (true) {
            getIn().waitData(0);
            next = (BBucket) getIn().popFirst();
            if (next != null) {
                break;
            } else if (getIn().isAppendClosed()) {
                return -1;
            } else {
                System.err.println("Spurious waitData signal, no data");
            }
        }
        chunk.append(next.array(), next.position(), next.remaining());
        int read =  next.remaining();
        next.release();
        return read;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.