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

io.github.sinri.keel.web.tcp.piece.KeelPieceKit Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

There is a newer version: 3.2.20
Show newest version
package io.github.sinri.keel.web.tcp.piece;

import io.vertx.core.buffer.Buffer;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;

/**
 * 配合 KeelSisiodosi 食用。
 *
 * @param 

* @since 2.8 */ public abstract class KeelPieceKit

implements Consumer { private final Queue

pieceQueue; private Buffer buffer; public KeelPieceKit() { this.buffer = Buffer.buffer(); this.pieceQueue = new ConcurrentLinkedQueue<>(); } protected Buffer getBuffer() { return buffer; } protected void cutBuffer(int newStart) { buffer = buffer.getBuffer(newStart, buffer.length()); } public Queue

getPieceQueue() { return pieceQueue; } /** * THREAD SAFE NEEDED */ @Override public void accept(Buffer incomingBuffer) { if (incomingBuffer != null && incomingBuffer.length() > 0) { buffer.appendBuffer(incomingBuffer); while (true) { P piece = this.parseFirstPieceFromBuffer(); if (piece == null) break; this.pieceQueue.offer(piece); } } } /** * Try to read first piece from buffer, * if piece found, save the rest buffer, return the piece; * or return null. * * @return first piece or null. * THREAD SAFE NEEDED. */ abstract protected P parseFirstPieceFromBuffer(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy